This is an automated email from the ASF dual-hosted git repository.
gopidesu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 92184c367a8 Fix: ignore connection schema when schema is none in mongo
hook (#53780)
92184c367a8 is described below
commit 92184c367a8e92aef0a2b1b6c8fc2de53eb00db6
Author: GPK <[email protected]>
AuthorDate: Sat Jul 26 10:27:03 2025 +0100
Fix: ignore connection schema when schema is none in mongo hook (#53780)
---
providers/mongo/src/airflow/providers/mongo/hooks/mongo.py | 6 +++++-
providers/mongo/tests/unit/mongo/hooks/test_mongo.py | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/providers/mongo/src/airflow/providers/mongo/hooks/mongo.py
b/providers/mongo/src/airflow/providers/mongo/hooks/mongo.py
index 664a9e20dfa..64e747fe2fd 100644
--- a/providers/mongo/src/airflow/providers/mongo/hooks/mongo.py
+++ b/providers/mongo/src/airflow/providers/mongo/hooks/mongo.py
@@ -212,7 +212,11 @@ class MongoHook(BaseHook):
netloc = f"{quote_plus(login)}:{quote_plus(password)}@{netloc}"
if self.connection.port:
netloc = f"{netloc}:{self.connection.port}"
- path = f"/{self.connection.schema}"
+
+ if self.connection.schema:
+ path = f"/{self.connection.schema}"
+ else:
+ path = ""
return urlunsplit((scheme, netloc, path, "", ""))
def get_collection(self, mongo_collection: str, mongo_db: str | None =
None) -> MongoCollection:
diff --git a/providers/mongo/tests/unit/mongo/hooks/test_mongo.py
b/providers/mongo/tests/unit/mongo/hooks/test_mongo.py
index f281d5d062f..2122895dea1 100644
--- a/providers/mongo/tests/unit/mongo/hooks/test_mongo.py
+++ b/providers/mongo/tests/unit/mongo/hooks/test_mongo.py
@@ -283,7 +283,7 @@ class TestMongoHook:
self.hook.connection.login = None
self.hook.connection.password = None
self.hook.connection.port = None
- assert self.hook._create_uri() == "mongodb://mongo/None"
+ assert self.hook._create_uri() == "mongodb://mongo"
def test_create_uri_srv_true(self):
self.hook.extras["srv"] = True