Skip to content
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

add unit test and move default logic to mashumaro hook #3305

Merged
merged 2 commits into from
Apr 28, 2021
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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## dbt 0.19.2 (tbd)
## dbt 0.19.2 (Release TBD)

#### Fixes
### Fixes
- Ensure that schema test macros are properly processed ([#3229](https:/fishtown-analytics/dbt/issues/3229), [#3272](https:/fishtown-analytics/dbt/pull/3272))
- Fix regression for default project/database for BigQuery connections ([#3218](https:/fishtown-analytics/dbt/issues/3218), [#3305](https:/fishtown-analytics/dbt/pull/3305))

## dbt 0.19.1 (March 31, 2021)

Expand Down
8 changes: 5 additions & 3 deletions plugins/bigquery/dbt/adapters/bigquery/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,17 @@ def _connection_keys(self):
return ('method', 'database', 'schema', 'location', 'priority',
'timeout_seconds', 'maximum_bytes_billed')

def __post_init__(self):
@classmethod
def __pre_deserialize__(cls, d: Dict[Any, Any]) -> Dict[Any, Any]:
# We need to inject the correct value of the database (aka project) at
# this stage, ref
# https:/fishtown-analytics/dbt/pull/2908#discussion_r532927436.

# `database` is an alias of `project` in BigQuery
if self.database is None:
if 'database' not in d:
_, database = get_bigquery_defaults()
self.database = database
d['database'] = database
return d


class BigQueryConnectionManager(BaseConnectionManager):
Expand Down
21 changes: 20 additions & 1 deletion test/unit/test_bigquery_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def setUp(self):
'priority': 'batch',
'maximum_bytes_billed': 0,
},
'oauth--no-project': {
'oauth-no-project': {
'type': 'bigquery',
'method': 'oauth',
'schema': 'dummy_schema',
Expand Down Expand Up @@ -144,6 +144,25 @@ def get_adapter(self, target):


class TestBigQueryAdapterAcquire(BaseTestBigQueryAdapter):
@patch('dbt.adapters.bigquery.connections.get_bigquery_defaults', return_value=('credentials', 'project_id'))
@patch('dbt.adapters.bigquery.BigQueryConnectionManager.open', return_value=_bq_conn())
def test_acquire_connection_oauth_no_project_validations(self, mock_open_connection, mock_get_bigquery_defaults):
adapter = self.get_adapter('oauth-no-project')
mock_get_bigquery_defaults.assert_called_once()
try:
connection = adapter.acquire_connection('dummy')
self.assertEqual(connection.type, 'bigquery')

except dbt.exceptions.ValidationException as e:
self.fail('got ValidationException: {}'.format(str(e)))

except BaseException as e:
raise

mock_open_connection.assert_not_called()
connection.handle
mock_open_connection.assert_called_once()

@patch('dbt.adapters.bigquery.BigQueryConnectionManager.open', return_value=_bq_conn())
def test_acquire_connection_oauth_validations(self, mock_open_connection):
adapter = self.get_adapter('oauth')
Expand Down