Skip to content

Commit

Permalink
Fix Snowflake hook conn id (#8423)
Browse files Browse the repository at this point in the history
Do not set manually to ensure the base `DbApiHook` correctly interprets
arguments based on `conn_name_attr` and `default_conn_name`.
  • Loading branch information
dhuang committed Apr 20, 2020
1 parent fe8f150 commit 297ad30
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,10 @@ If the DAG relies on tasks with other trigger rules (i.e. `all_done`) being skip
The goal of this change is to achieve a more consistent and configurale cascading behaviour based on the `BaseBranchOperator` (see [AIRFLOW-2923](https://jira.apache.org/jira/browse/AIRFLOW-2923) and [AIRFLOW-1784](https://jira.apache.org/jira/browse/AIRFLOW-1784)).
### Change default snowflake_conn_id for Snowflake hook and operators
When initializing a Snowflake hook or operator, the value used for `snowflake_conn_id` was always `snowflake_conn_id`, regardless of whether or not you specified a value for it. The default `snowflake_conn_id` value is now switched to `snowflake_default` for consistency and will be properly overriden when specified.
## Airflow 1.10.10
### Setting Empty string to a Airflow Variable will return an empty string
Expand Down
7 changes: 3 additions & 4 deletions airflow/providers/snowflake/hooks/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ def __init__(self, *args, **kwargs):
self.region = kwargs.pop("region", None)
self.role = kwargs.pop("role", None)
self.schema = kwargs.pop("schema", None)
self.snowflake_conn_id = 'snowflake_conn_id'

def _get_conn_params(self):
"""
one method to fetch connection params as a dict
used in get_uri() and get_connection()
"""
conn = self.get_connection(self.snowflake_conn_id)
conn = self.get_connection(self.snowflake_conn_id) # pylint: disable=no-member
account = conn.extra_dejson.get('account', '')
warehouse = conn.extra_dejson.get('warehouse', '')
database = conn.extra_dejson.get('database', '')
Expand Down Expand Up @@ -119,8 +118,8 @@ def _get_aws_credentials(self):
intended to be used by external import and export statements
"""
if self.snowflake_conn_id:
connection_object = self.get_connection(self.snowflake_conn_id)
if self.snowflake_conn_id: # pylint: disable=no-member
connection_object = self.get_connection(self.snowflake_conn_id) # pylint: disable=no-member
if 'aws_secret_access_key' in connection_object.extra_dejson:
aws_access_key_id = connection_object.extra_dejson.get(
'aws_access_key_id')
Expand Down
1 change: 1 addition & 0 deletions tests/providers/snowflake/hooks/test_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def test_get_conn_params(self):
'warehouse': 'af_wh',
'region': 'af_region',
'role': 'af_role'}
self.assertEqual(self.db_hook.snowflake_conn_id, 'snowflake_default') # pylint: disable=no-member
self.assertEqual(conn_params_shouldbe, self.db_hook._get_conn_params())

def test_get_conn(self):
Expand Down

0 comments on commit 297ad30

Please sign in to comment.