This is an automated email from the ASF dual-hosted git repository.
potiuk 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 8a4cfd7 OdbcHook returns None. Related to #15016 issue. (#15510)
8a4cfd7 is described below
commit 8a4cfd734127855c6de3236fddbcaba1bd96060e
Author: Vyacheslav <[email protected]>
AuthorDate: Sun Jun 13 13:49:13 2021 +0200
OdbcHook returns None. Related to #15016 issue. (#15510)
* OdbcHook returns None. Related to #15016 issue.
This PR is related to #15016 issue.
OdbcHook returns None for non-boolean-like string values in connect_kwargs
dict arg, however connect_kwarg values should remain as is in this case.
According to the discussion on #15016, we agreed to remove the clean_bool
function, as it is not needed actually for processing boolean values in JSON .
---
airflow/providers/odbc/hooks/odbc.py | 14 +-------------
docs/apache-airflow-providers-odbc/connections/odbc.rst | 4 ++--
tests/providers/odbc/hooks/test_odbc.py | 2 +-
3 files changed, 4 insertions(+), 16 deletions(-)
diff --git a/airflow/providers/odbc/hooks/odbc.py
b/airflow/providers/odbc/hooks/odbc.py
index 73210fa..79b6393 100644
--- a/airflow/providers/odbc/hooks/odbc.py
+++ b/airflow/providers/odbc/hooks/odbc.py
@@ -160,20 +160,8 @@ class OdbcHook(DbApiHook):
Hook ``connect_kwargs`` precedes ``connect_kwargs`` from conn extra.
- String values for 'true' and 'false' are converted to bool type.
-
If ``attrs_before`` provided, keys and values are converted to int, as
required by pyodbc.
"""
-
- def clean_bool(val): # pylint: disable=inconsistent-return-statements
- if hasattr(val, 'lower'):
- if val.lower() == 'true':
- return True
- elif val.lower() == 'false':
- return False
- else:
- return val
-
conn_connect_kwargs =
self.connection_extra_lower.get('connect_kwargs', {})
hook_connect_kwargs = self._connect_kwargs or {}
merged_connect_kwargs = merge_dicts(conn_connect_kwargs,
hook_connect_kwargs)
@@ -183,7 +171,7 @@ class OdbcHook(DbApiHook):
int(k): int(v) for k, v in
merged_connect_kwargs['attrs_before'].items()
}
- return {k: clean_bool(v) for k, v in merged_connect_kwargs.items()}
+ return merged_connect_kwargs
def get_conn(self) -> pyodbc.Connection:
"""Returns a pyodbc connection object."""
diff --git a/docs/apache-airflow-providers-odbc/connections/odbc.rst
b/docs/apache-airflow-providers-odbc/connections/odbc.rst
index 33d6305..e4bd83c 100644
--- a/docs/apache-airflow-providers-odbc/connections/odbc.rst
+++ b/docs/apache-airflow-providers-odbc/connections/odbc.rst
@@ -111,8 +111,8 @@ Extra (optional)
"ApplicationIntent": "ReadOnly",
"TrustedConnection": "Yes",
"connect_kwargs": {
- "autocommit": "false",
- "ansi": "true"
+ "autocommit": false,
+ "ansi": true
}
}
diff --git a/tests/providers/odbc/hooks/test_odbc.py
b/tests/providers/odbc/hooks/test_odbc.py
index 8ce89b2..abcf5bb 100644
--- a/tests/providers/odbc/hooks/test_odbc.py
+++ b/tests/providers/odbc/hooks/test_odbc.py
@@ -166,7 +166,7 @@ class TestOdbcHook:
"""
Bools will be parsed from uri as strings
"""
- conn_extra = json.dumps(dict(connect_kwargs={'ansi': 'true'}))
+ conn_extra = json.dumps(dict(connect_kwargs={'ansi': True}))
hook = self.get_hook(conn_params=dict(extra=conn_extra))
assert hook.connect_kwargs == {
'ansi': True,