From f8580a23ff8122c3fe282f1d6eff39be27528d32 Mon Sep 17 00:00:00 2001 From: Jacob Beck Date: Mon, 4 May 2020 10:09:11 -0600 Subject: [PATCH] Suppress the bigquery job sql in exception messages --- CHANGELOG.md | 1 + .../dbt/adapters/bigquery/connections.py | 10 +++++- .../location-models/model.sql | 1 + .../test_bigquery_location_change.py | 31 +++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/integration/022_bigquery_test/location-models/model.sql create mode 100644 test/integration/022_bigquery_test/test_bigquery_location_change.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b1263d5a18..7b84a3deaab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/plugins/bigquery/dbt/adapters/bigquery/connections.py b/plugins/bigquery/dbt/adapters/bigquery/connections.py index 98b0d839763..ac16068644a 100644 --- a/plugins/bigquery/dbt/adapters/bigquery/connections.py +++ b/plugins/bigquery/dbt/adapters/bigquery/connections.py @@ -20,6 +20,9 @@ from hologram.helpers import StrEnum +BQ_QUERY_JOB_SPLIT = '-----Query Job SQL Follows-----' + + class Priority(StrEnum): Interactive = 'interactive' Batch = 'batch' @@ -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 diff --git a/test/integration/022_bigquery_test/location-models/model.sql b/test/integration/022_bigquery_test/location-models/model.sql new file mode 100644 index 00000000000..43258a71464 --- /dev/null +++ b/test/integration/022_bigquery_test/location-models/model.sql @@ -0,0 +1 @@ +select 1 as id diff --git a/test/integration/022_bigquery_test/test_bigquery_location_change.py b/test/integration/022_bigquery_test/test_bigquery_location_change.py new file mode 100644 index 00000000000..d88f29b2855 --- /dev/null +++ b/test/integration/022_bigquery_test/test_bigquery_location_change.py @@ -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