Skip to content

Commit

Permalink
Chore: Fix linter on MongoDB adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jan 17, 2025
1 parent 3a5a8d8 commit 649feba
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cratedb_toolkit/io/mongodb/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 649feba

Please sign in to comment.