From a99f4b1e98459af4f004f05d2f3ae86bb78a3733 Mon Sep 17 00:00:00 2001 From: Jeremy Yeo Date: Thu, 14 Oct 2021 21:22:20 +1300 Subject: [PATCH 1/4] raise profile error --- dbt/adapters/bigquery/connections.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dbt/adapters/bigquery/connections.py b/dbt/adapters/bigquery/connections.py index 265959400..d6988103c 100644 --- a/dbt/adapters/bigquery/connections.py +++ b/dbt/adapters/bigquery/connections.py @@ -21,10 +21,11 @@ from dbt.adapters.bigquery import gcloud from dbt.utils import format_bytes, format_rows_number from dbt.clients import agate_helper +from dbt.config.profile import INVALID_PROFILE_MESSAGE from dbt.tracking import active_user from dbt.contracts.connection import ConnectionState, AdapterResponse from dbt.exceptions import ( - FailedToConnectException, RuntimeException, DatabaseException + FailedToConnectException, RuntimeException, DatabaseException, DbtProfileError ) from dbt.adapters.base import BaseConnectionManager, Credentials from dbt.logger import GLOBAL_LOGGER as logger @@ -58,7 +59,11 @@ def get_bigquery_defaults(scopes=None) -> Tuple[Any, Optional[str]]: project_id is returned available from the environment; otherwise None """ # Cached, because the underlying implementation shells out, taking ~1s - return google.auth.default(scopes=scopes) + try: + credentials, _ = google.auth.default(scopes=scopes) + return credentials, _ + except google.auth.exceptions.DefaultCredentialsError as e: + raise DbtProfileError(INVALID_PROFILE_MESSAGE.format(error_string=e)) class Priority(StrEnum): From 636a88af497184f578be683a533a06fc85beaa7a Mon Sep 17 00:00:00 2001 From: Jeremy Yeo Date: Mon, 18 Oct 2021 21:54:23 +1300 Subject: [PATCH 2/4] add deps test --- tests/integration/dbt_deps_test/test_deps.py | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/integration/dbt_deps_test/test_deps.py diff --git a/tests/integration/dbt_deps_test/test_deps.py b/tests/integration/dbt_deps_test/test_deps.py new file mode 100644 index 000000000..30a81636c --- /dev/null +++ b/tests/integration/dbt_deps_test/test_deps.py @@ -0,0 +1,35 @@ +from tests.integration.base import DBTIntegrationTest, use_profile +import os +import re +import yaml + +import pytest + + +class TestDeps(DBTIntegrationTest): + @property + def schema(self): + return "dbt_deps" + + @staticmethod + def dir(value): + return os.path.normpath(value) + + @property + def models(self): + return "models" + + @pytest.fixture(autouse=True) + def capsys(self, capsys): + self.capsys = capsys + + @use_profile("bigquery") + def test_bigquery_ok(self): + self.run_dbt(["deps"]) + self.assertNotIn("ERROR", self.capsys.readouterr().out) + + +class TestDepsProfileVariable(TestDeps): + @property + def project_config(self): + return {"config-version": 2, "profile": '{{ "te" ~ "st" }}'} From 079eba96e40e3afa1a6d739f1dfc2dce34e4ec1c Mon Sep 17 00:00:00 2001 From: Jeremy Yeo Date: Fri, 22 Oct 2021 17:19:26 +1300 Subject: [PATCH 3/4] remove test --- tests/integration/dbt_deps_test/test_deps.py | 35 -------------------- 1 file changed, 35 deletions(-) delete mode 100644 tests/integration/dbt_deps_test/test_deps.py diff --git a/tests/integration/dbt_deps_test/test_deps.py b/tests/integration/dbt_deps_test/test_deps.py deleted file mode 100644 index 30a81636c..000000000 --- a/tests/integration/dbt_deps_test/test_deps.py +++ /dev/null @@ -1,35 +0,0 @@ -from tests.integration.base import DBTIntegrationTest, use_profile -import os -import re -import yaml - -import pytest - - -class TestDeps(DBTIntegrationTest): - @property - def schema(self): - return "dbt_deps" - - @staticmethod - def dir(value): - return os.path.normpath(value) - - @property - def models(self): - return "models" - - @pytest.fixture(autouse=True) - def capsys(self, capsys): - self.capsys = capsys - - @use_profile("bigquery") - def test_bigquery_ok(self): - self.run_dbt(["deps"]) - self.assertNotIn("ERROR", self.capsys.readouterr().out) - - -class TestDepsProfileVariable(TestDeps): - @property - def project_config(self): - return {"config-version": 2, "profile": '{{ "te" ~ "st" }}'} From 751a18ee89fc2becf3a1b7c5cbd051753bc475ec Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Fri, 22 Oct 2021 10:20:51 +0200 Subject: [PATCH 4/4] Add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ef13dea2..029b7f82a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,12 @@ ### Fixes - Reimplement the `unique` test to handle column expressions and naming overlaps ([#33](https://github.com/dbt-labs/dbt-bigquery/issues/33), [#35](https://github.com/dbt-labs/dbt-bigquery/issues/35), [#10](https://github.com/dbt-labs/dbt-bigquery/pull/10)) +- Avoid error in `dbt deps` + `dbt clean` if default project is missing ([#27](https://github.com/dbt-labs/dbt-bigquery/issues/27), [#40](https://github.com/dbt-labs/dbt-bigquery/pull/40)) ### Contributors - [@DigUpTheHatchet](https://github.com/DigUpTheHatchet) ([#10](https://github.com/dbt-labs/dbt-bigquery/pull/10)) +- [@jeremyyeo](https://github.com/jeremyyeo) ([#40](https://github.com/dbt-labs/dbt-bigquery/pull/40)) ## dbt-bigquery 1.0.0b1 (October 11, 2021)