This is an automated email from the ASF dual-hosted git repository.

rom 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 fda45143cde fix(providers/mongo): prevent applying lower method on 
boolean field (#43024)
fda45143cde is described below

commit fda45143cde4884b89ccf59edc7b50e4dfd79c37
Author: Josix <[email protected]>
AuthorDate: Thu Oct 17 02:57:49 2024 +0800

    fix(providers/mongo): prevent applying lower method on boolean field 
(#43024)
---
 providers/src/airflow/providers/mongo/hooks/mongo.py |  6 +++---
 providers/tests/mongo/hooks/test_mongo.py            | 12 ++++++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/providers/src/airflow/providers/mongo/hooks/mongo.py 
b/providers/src/airflow/providers/mongo/hooks/mongo.py
index 63b981df9ef..a15cc45491d 100644
--- a/providers/src/airflow/providers/mongo/hooks/mongo.py
+++ b/providers/src/airflow/providers/mongo/hooks/mongo.py
@@ -136,10 +136,10 @@ class MongoHook(BaseHook):
         self.client: MongoClient | None = None
         self.uri = self._create_uri()
 
-        self.allow_insecure = self.extras.pop("allow_insecure", 
"false").lower() == "true"
+        self.allow_insecure = str(self.extras.pop("allow_insecure", 
"false")).lower() == "true"
         self.ssl_enabled = (
-            self.extras.get("ssl", "false").lower() == "true"
-            or self.extras.get("tls", "false").lower() == "true"
+            str(self.extras.get("ssl", "false")).lower() == "true"
+            or str(self.extras.get("tls", "false")).lower() == "true"
         )
 
         if self.ssl_enabled and not self.allow_insecure:
diff --git a/providers/tests/mongo/hooks/test_mongo.py 
b/providers/tests/mongo/hooks/test_mongo.py
index 01e58f6081e..5a284b69cc2 100644
--- a/providers/tests/mongo/hooks/test_mongo.py
+++ b/providers/tests/mongo/hooks/test_mongo.py
@@ -63,6 +63,12 @@ def mongo_connections():
             port=27017,
             extra='{"srv": true}',
         ),
+        Connection(
+            conn_id="mongo_default_with_allow_insecure_ssl_fields",
+            conn_type="mongo",
+            host="mongo",
+            extra='{"allow_insecure": false, "ssl": true}',
+        ),
         # Mongo establishes connection during initialization, so we need to 
have this connection
         Connection(conn_id="fake_connection", conn_type="mongo", host="mongo", 
port=27017),
     ]
@@ -400,3 +406,9 @@ def test_context_manager():
         assert ctx_hook.client is not None
 
     assert ctx_hook.client is None
+
+
+def test_allow_insecure_and_ssl_enabled():
+    hook = 
MongoHook(mongo_conn_id="mongo_default_with_allow_insecure_ssl_fields")
+    assert hook.allow_insecure is False
+    assert hook.ssl_enabled is True

Reply via email to