Skip to content

Commit fa36540

Browse files
committed
-
1 parent 8573f33 commit fa36540

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

databricks/sdk/config.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,25 @@ def client_type(self) -> ClientType:
383383
384384
This is separate from host_type. For example, a unified host can support both
385385
workspace and account client types.
386+
387+
Returns ClientType.ACCOUNT or ClientType.WORKSPACE based on the configuration.
388+
389+
For unified hosts, account_id must be set. If workspace_id is also set,
390+
returns WORKSPACE, otherwise returns ACCOUNT.
386391
"""
387-
# If workspace_id is set, this is a workspace client
388-
if self.workspace_id:
392+
host_type = self.host_type
393+
394+
if host_type == HostType.ACCOUNTS:
395+
return ClientType.ACCOUNT
396+
397+
if host_type == HostType.WORKSPACE:
389398
return ClientType.WORKSPACE
390399

391-
# If account_id is set and no workspace_id, this is an account client
392-
if self.account_id:
400+
if host_type == HostType.UNIFIED:
401+
if not self.account_id:
402+
raise ValueError("Unified host requires account_id to be set")
403+
if self.workspace_id:
404+
return ClientType.WORKSPACE
393405
return ClientType.ACCOUNT
394406

395407
# Default to workspace for backward compatibility
@@ -463,9 +475,7 @@ def oidc_endpoints(self) -> Optional[OidcEndpoints]:
463475
# Handle unified hosts
464476
if self.host_type == HostType.UNIFIED:
465477
if not self.account_id:
466-
raise ValueError(
467-
"Unified host requires account_id to be set for OAuth endpoints"
468-
)
478+
raise ValueError("Unified host requires account_id to be set for OAuth endpoints")
469479
return get_unified_endpoints(self.host, self.account_id)
470480

471481
# Handle traditional account hosts

tests/test_config.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,11 @@ def test_host_type_unified():
293293

294294

295295
def test_client_type_workspace():
296-
"""Test that client type is workspace when workspace_id is set."""
296+
"""Test that client type is workspace when workspace_id is set on unified host."""
297297
config = Config(
298298
host="https://unified.databricks.com",
299299
workspace_id="test-workspace",
300+
account_id="test-account",
300301
experimental_is_unified_host=True,
301302
token="test-token",
302303
)
@@ -320,6 +321,27 @@ def test_client_type_workspace_default():
320321
assert config.client_type == ClientType.WORKSPACE
321322

322323

324+
def test_client_type_accounts_host():
325+
"""Test that client type is account for accounts host."""
326+
config = Config(
327+
host="https://accounts.cloud.databricks.com",
328+
account_id="test-account",
329+
token="test-token",
330+
)
331+
assert config.client_type == ClientType.ACCOUNT
332+
333+
334+
def test_client_type_unified_without_account_id():
335+
"""Test that client type raises error for unified host without account_id."""
336+
config = Config(
337+
host="https://unified.databricks.com",
338+
experimental_is_unified_host=True,
339+
token="test-token",
340+
)
341+
with pytest.raises(ValueError, match="Unified host requires account_id"):
342+
_ = config.client_type
343+
344+
323345
def test_is_account_client_backward_compatibility():
324346
"""Test that is_account_client property still works for backward compatibility."""
325347
config_workspace = Config(host="https://test.databricks.com", token="test-token")

0 commit comments

Comments
 (0)