From 35bffecbecaad5397d4a556b37f4e5665b1c266f Mon Sep 17 00:00:00 2001 From: Ben Cassell <98852248+benc-db@users.noreply.github.com> Date: Wed, 19 Feb 2025 09:06:25 -0800 Subject: [PATCH] Lazy init api client for connection manager to fix 940 (#941) --- CHANGELOG.md | 4 ++++ dbt/adapters/databricks/connections.py | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6cefd9c..a88c5413 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## dbt-databricks 1.9.6 (TBD) +### Fixes + +- Fix for parse raising error for not having credentials ([941](https://github.com/databricks/dbt-databricks/pull/941)) + ### Under the Hood - Refactoring of some connection internals ([929](https://github.com/databricks/dbt-databricks/pull/929)) diff --git a/dbt/adapters/databricks/connections.py b/dbt/adapters/databricks/connections.py index 56bf196c..ccf32c98 100644 --- a/dbt/adapters/databricks/connections.py +++ b/dbt/adapters/databricks/connections.py @@ -202,12 +202,19 @@ class DatabricksConnectionManager(SparkConnectionManager): def __init__(self, profile: AdapterRequiredConfig, mp_context: SpawnContext): super().__init__(profile, mp_context) - creds = cast(DatabricksCredentials, self.profile.credentials) - self.api_client = DatabricksApiClient.create(creds, 15 * 60) + self._api_client: Optional[DatabricksApiClient] = None self.threads_compute_connections: dict[ Hashable, dict[Hashable, DatabricksDBTConnection] ] = {} + @property + def api_client(self) -> DatabricksApiClient: + if self._api_client is None: + self._api_client = DatabricksApiClient.create( + cast(DatabricksCredentials, self.profile.credentials), 15 * 60 + ) + return self._api_client + def cancel_open(self) -> list[str]: cancelled = super().cancel_open() logger.info("Cancelling open python jobs")