Skip to content

Commit

Permalink
Lazy init api client for connection manager to fix 940 (#941)
Browse files Browse the repository at this point in the history
  • Loading branch information
benc-db authored Feb 19, 2025
1 parent 2ccd729 commit 35bffec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
11 changes: 9 additions & 2 deletions dbt/adapters/databricks/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 35bffec

Please sign in to comment.