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

Suppress the bigquery job sql in exception messages (#2383) #2393

Merged
merged 1 commit into from
May 4, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- Fix an issue where BigQuery incorrectly used a relation's quote policy as the basis for the information schema's include policy, instead of the relation's include policy. ([#2188](https://github.com/fishtown-analytics/dbt/issues/2188), [#2325](https://github.com/fishtown-analytics/dbt/pull/2325))
- Fix "dbt deps" command so it respects the "--project-dir" arg if specified. ([#2338](https://github.com/fishtown-analytics/dbt/issues/2338), [#2339](https://github.com/fishtown-analytics/dbt/issues/2339))
- On `run_cli` API calls that are passed `--vars` differing from the server's `--vars`, the RPC server rebuilds the manifest for that call. ([#2265](https://github.com/fishtown-analytics/dbt/issues/2265), [#2363](https://github.com/fishtown-analytics/dbt/pull/2363))
- Remove the query job SQL from bigquery exceptions ([#2383](https://github.com/fishtown-analytics/dbt/issues/2383), [#2393](https://github.com/fishtown-analytics/dbt/pull/2393))
- Fix "Object of type Decimal is not JSON serializable" error when BigQuery queries returned numeric types in nested data structures ([#2336](https://github.com/fishtown-analytics/dbt/issues/2336), [#2348](https://github.com/fishtown-analytics/dbt/pull/2348))
- No longer query the information_schema.schemata view on bigquery ([#2320](https://github.com/fishtown-analytics/dbt/issues/2320), [#2382](https://github.com/fishtown-analytics/dbt/pull/2382))
- Add support for `sql_header` config in incremental models ([#2136](https://github.com/fishtown-analytics/dbt/issues/2136), [#2200](https://github.com/fishtown-analytics/dbt/pull/2200))
Expand Down
10 changes: 9 additions & 1 deletion plugins/bigquery/dbt/adapters/bigquery/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
from hologram.helpers import StrEnum


BQ_QUERY_JOB_SPLIT = '-----Query Job SQL Follows-----'


class Priority(StrEnum):
Interactive = 'interactive'
Batch = 'batch'
Expand Down Expand Up @@ -95,7 +98,12 @@ def exception_handler(self, sql):
# this sounds a lot like a signal handler and probably has
# useful information, so raise it without modification.
raise
raise RuntimeException(str(e))
exc_message = str(e)
# the google bigquery library likes to add the query log, which we
# don't want to log. Hopefully they never change this!
if BQ_QUERY_JOB_SPLIT in exc_message:
exc_message = exc_message.split(BQ_QUERY_JOB_SPLIT)[0].strip()
raise RuntimeException(exc_message)

def cancel_open(self) -> None:
pass
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 1 as id
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from test.integration.base import DBTIntegrationTest, use_profile
import os


class TestBigqueryErrorHandling(DBTIntegrationTest):
def setUp(self):
self.valid_location = os.getenv('DBT_TEST_BIGQUERY_INITIAL_LOCATION', 'US')
self.invalid_location = os.getenv('DBT_TEST_BIGQUERY_BAD_LOCATION', 'northamerica-northeast1')
self.location = self.valid_location
super().setUp()

@property
def schema(self):
return "bigquery_test_022"

@property
def models(self):
return "location-models"

def bigquery_profile(self):
result = super().bigquery_profile()
result['test']['outputs']['default2']['location'] = self.location
return result

@use_profile('bigquery')
def test_bigquery_location_invalid(self):
self.run_dbt()
self.location = self.invalid_location
self.use_profile('bigquery')
_, stdout = self.run_dbt_and_capture(expect_pass=False)
assert 'Query Job SQL Follows' not in stdout