This is an automated email from the ASF dual-hosted git repository.
kaxil 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 a58f636b9f2 Fix false driver warning in `OdbcHook` when extra driver
is not set (#77248)
a58f636b9f2 is described below
commit a58f636b9f2c8a6f030d6a53f5f84880a09fe880
Author: Marco C. <[email protected]>
AuthorDate: Sat Nov 21 00:27:17 2026 +0000
Fix false driver warning in `OdbcHook` when extra driver is not set (#77248)
---
.../odbc/src/airflow/providers/odbc/hooks/odbc.py | 21 +++++++++++----------
providers/odbc/tests/unit/odbc/hooks/test_odbc.py | 8 ++++++--
2 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/providers/odbc/src/airflow/providers/odbc/hooks/odbc.py
b/providers/odbc/src/airflow/providers/odbc/hooks/odbc.py
index 4226fe8bb7f..3c91ed83dcc 100644
--- a/providers/odbc/src/airflow/providers/odbc/hooks/odbc.py
+++ b/providers/odbc/src/airflow/providers/odbc/hooks/odbc.py
@@ -99,16 +99,17 @@ class OdbcHook(DbApiHook):
extra_driver = self.connection_extra_lower.get("driver")
from airflow.providers.common.compat.sdk import conf
- if extra_driver and conf.getboolean("providers.odbc",
"allow_driver_in_extra", fallback=False):
- self._driver = extra_driver
- else:
- self.log.warning(
- "You have supplied 'driver' via connection extra but it will
not be used. In order to "
- "use 'driver' from extra you must set airflow config setting
`allow_driver_in_extra = True` "
- "in section `providers.odbc`. Alternatively you may specify
driver via 'driver' parameter of "
- "the hook constructor or via 'hook_params' dictionary with key
'driver' if using SQL "
- "operators."
- )
+ if extra_driver:
+ if conf.getboolean("providers.odbc", "allow_driver_in_extra",
fallback=False):
+ self._driver = extra_driver
+ else:
+ self.log.warning(
+ "You have supplied 'driver' via connection extra but it
will not be used. In order to "
+ "use 'driver' from extra you must set airflow config
setting `allow_driver_in_extra = True` "
+ "in section `providers.odbc`. Alternatively you may
specify driver via 'driver' parameter of "
+ "the hook constructor or via 'hook_params' dictionary with
key 'driver' if using SQL "
+ "operators."
+ )
if not self._driver:
self._driver = self.default_driver
return self._driver.strip().lstrip("{").rstrip("}").strip() if
self._driver else None
diff --git a/providers/odbc/tests/unit/odbc/hooks/test_odbc.py
b/providers/odbc/tests/unit/odbc/hooks/test_odbc.py
index 5599c7212dc..0d930587b9e 100644
--- a/providers/odbc/tests/unit/odbc/hooks/test_odbc.py
+++ b/providers/odbc/tests/unit/odbc/hooks/test_odbc.py
@@ -252,10 +252,14 @@ class TestOdbcHook:
assert conf.getboolean("providers.odbc", "allow_driver_in_extra") is
False
- def test_default_driver_set(self):
- with patch.object(OdbcHook, "default_driver", "Blah driver"):
+ def test_default_driver_set(self, caplog):
+ with (
+ patch.object(OdbcHook, "default_driver", "Blah driver"),
+ caplog.at_level(logging.WARNING,
logger="airflow.providers.odbc.hooks.odbc"),
+ ):
hook = mock_db_hook(OdbcHook)
assert hook.driver == "Blah driver"
+ assert "You have supplied 'driver' via connection extra" not in
caplog.text
def test_driver_extra_works_when_default_driver_set(self):
with patch.object(OdbcHook, "default_driver", "Blah driver"):