From da3a9f9bd798c27c1efc484e515db1c463236a36 Mon Sep 17 00:00:00 2001 From: Mila Page <67295367+VersusFacit@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:39:57 -0700 Subject: [PATCH] Propose fix for connection testing issues in Cloud. (#836) Co-authored-by: Ben Cassell --- CHANGELOG.md | 1 + dbt/adapters/databricks/impl.py | 14 ++++++++++---- .../functional/adapter/columns/test_get_columns.py | 3 +++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb759c85..457c871b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Fix places where we were not properly closing cursors, and other test warnings ([713](https://github.com/databricks/dbt-databricks/pull/713)) - Drop support for Python 3.8 ([713](https://github.com/databricks/dbt-databricks/pull/713)) - Upgrade databricks-sql-connector dependency to 3.5.0 ([833](https://github.com/databricks/dbt-databricks/pull/833)) +- Fix behavior flag use in init of DatabricksAdapter ([836](https://github.com/databricks/dbt-databricks/pull/836/files)) ## dbt-databricks 1.8.7 (October 10, 2024) diff --git a/dbt/adapters/databricks/impl.py b/dbt/adapters/databricks/impl.py index b275aa4f..4432093d 100644 --- a/dbt/adapters/databricks/impl.py +++ b/dbt/adapters/databricks/impl.py @@ -85,6 +85,7 @@ from dbt_common.behavior_flags import BehaviorFlag from dbt_common.utils import executor from dbt_common.utils.dict import AttrDict +from dbt_common.exceptions import CompilationError from dbt_common.exceptions import DbtConfigError from dbt_common.exceptions import DbtInternalError from dbt_common.contracts.config.base import BaseConfig @@ -182,10 +183,15 @@ class DatabricksAdapter(SparkAdapter): def __init__(self, config: Any, mp_context: SpawnContext) -> None: super().__init__(config, mp_context) - if self.behavior.use_info_schema_for_columns.no_warn: # type: ignore[attr-defined] - self.get_column_behavior = GetColumnsByInformationSchema() - else: - self.get_column_behavior = GetColumnsByDescribe() + + # dbt doesn't propogate flags for certain workflows like dbt debug so this requires + # an additional guard + self.get_column_behavior = GetColumnsByDescribe() + try: + if self.behavior.use_info_schema_for_columns.no_warn: # type: ignore[attr-defined] + self.get_column_behavior = GetColumnsByInformationSchema() + except CompilationError: + pass @property def _behavior_flags(self) -> List[BehaviorFlag]: diff --git a/tests/functional/adapter/columns/test_get_columns.py b/tests/functional/adapter/columns/test_get_columns.py index cf0a9e24..04e73a66 100644 --- a/tests/functional/adapter/columns/test_get_columns.py +++ b/tests/functional/adapter/columns/test_get_columns.py @@ -13,6 +13,9 @@ def models(self): @pytest.fixture(scope="class", autouse=True) def setup(self, project): + # debug uses different rules for managing project flags than run + util.run_dbt(["debug", "--connection"]) + util.run_dbt(["run"]) @pytest.fixture(scope="class")