Skip to content

Fix #21096: Support boolean in extra__snowflake__insecure_mode #21155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion airflow/providers/snowflake/hooks/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
from airflow.utils.strings import to_boolean


def _try_to_boolean(value: Any):
if isinstance(value, (str, type(None))):
return to_boolean(value)
return value


class SnowflakeHook(DbApiHook):
"""
A client to interact with Snowflake.
Expand Down Expand Up @@ -157,7 +163,7 @@ def _get_conn_params(self) -> Dict[str, Optional[str]]:
schema = conn.schema or ''
authenticator = conn.extra_dejson.get('authenticator', 'snowflake')
session_parameters = conn.extra_dejson.get('session_parameters')
insecure_mode = to_boolean(
insecure_mode = _try_to_boolean(
conn.extra_dejson.get(
'extra__snowflake__insecure_mode', conn.extra_dejson.get('insecure_mode', None)
)
Expand Down
26 changes: 26 additions & 0 deletions tests/providers/snowflake/hooks/test_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,32 @@ class TestPytestSnowflakeHook:
'warehouse': 'af_wh',
},
),
(
{
**BASE_CONNECTION_KWARGS,
'extra': {
**BASE_CONNECTION_KWARGS['extra'],
'extra__snowflake__insecure_mode': False,
},
},
(
'snowflake://user:pw@airflow.af_region/db/public?'
'application=AIRFLOW&authenticator=snowflake&role=af_role&warehouse=af_wh'
),
{
'account': 'airflow',
'application': 'AIRFLOW',
'authenticator': 'snowflake',
'database': 'db',
'password': 'pw',
'region': 'af_region',
'role': 'af_role',
'schema': 'public',
'session_parameters': None,
'user': 'user',
'warehouse': 'af_wh',
},
),
],
)
def test_hook_should_support_prepare_basic_conn_params_and_uri(
Expand Down