From 649febabe4953a41e020a4990ab7db90772cb0c3 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Fri, 17 Jan 2025 23:29:10 +0100 Subject: [PATCH] Chore: Fix linter on MongoDB adapter --- cratedb_toolkit/io/mongodb/adapter.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cratedb_toolkit/io/mongodb/adapter.py b/cratedb_toolkit/io/mongodb/adapter.py index e7a40699..3f0c02c6 100644 --- a/cratedb_toolkit/io/mongodb/adapter.py +++ b/cratedb_toolkit/io/mongodb/adapter.py @@ -33,7 +33,7 @@ class MongoDBAdapterBase: address: DatabaseAddress effective_url: URL database_name: str - collection_name: str + collection_name: t.Optional[str] _custom_query_parameters = ["batch-size", "direct", "filter", "limit", "offset", "timeout"] _default_timeout = 5000 @@ -53,6 +53,8 @@ def from_url(cls, url: t.Union[str, boltons.urlutils.URL, yarl.URL]): timeout = mongodb_uri.query_params.pop("timeout", cls._default_timeout) for custom_query_parameter in cls._custom_query_parameters: mongodb_uri.query_params.pop(custom_query_parameter, None) + if not mongodb_database: + raise ValueError("MongoDB database not specified") return cls( address=mongodb_address, effective_url=mongodb_uri, @@ -231,6 +233,8 @@ def subscribe_cdc(self, resume_after: t.Optional[DocumentDict] = None): ) def create_collection(self): + if not self.collection_name: + raise ValueError("MongoDB collection not specified") self._mongodb_database.create_collection(self.collection_name) self._mongodb_collection = self._mongodb_database.get_collection(self.collection_name) return self._mongodb_collection