Skip to content

Commit b2d0839

Browse files
committed
Update hand-written files for X-Databricks-Workspace-Id header
Generator can't touch these (no DO NOT EDIT marker), or need post-generation reformatting because the new literal is longer: - config.py: SQL HTTP path resolver header read + widen workspace_id field comment (now accepts non-classic workspace identifier formats) - mixins/workspace.py: upload/download header injection (2 sites) - mixins/sharing.py: shares-list header injection - mixins/files.py: storage-proxy workspace probe (2 sites) - tests/test_config.py: renamed three header tests (test_workspace_org_id_header_* -> test_workspace_id_header_*, test_no_org_id_header_* -> test_no_workspace_id_header_*) and swapped asserted literals/docstrings - tests/test_files.py: updated mock response header fixtures - tests/integration/test_unified_profile.py: comment refresh - NEXT_CHANGELOG.md: internal-changes entry - __init__.py: black-wrap of the get_workspace_id() probe line that exceeded 120 chars after the longer literal substitution Signed-off-by: Divyansh Vijayvergia <divyansh.vijayvergia@databricks.com>
1 parent 9ca0020 commit b2d0839

9 files changed

Lines changed: 31 additions & 22 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414

1515
### Internal Changes
1616

17+
* Switch workspace addressing header on workspace-scoped API calls from `X-Databricks-Org-Id` to `X-Databricks-Workspace-Id`. The value continues to come from `Config.workspace_id` (`DATABRICKS_WORKSPACE_ID`), and now accepts either a classic numeric workspace ID or another workspace identifier format (server disambiguates).
18+
1719
### API Changes

databricks/sdk/__init__.py

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

databricks/sdk/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ def with_user_agent_extra(key: str, value: str):
8989
class Config:
9090
host: str = ConfigAttribute(env="DATABRICKS_HOST")
9191
account_id: str = ConfigAttribute(env="DATABRICKS_ACCOUNT_ID")
92+
# Workspace identifier sent on workspace-scoped API calls so unified hosts
93+
# can route to the right workspace. Accepts a classic numeric workspace ID
94+
# or another workspace identifier format that the server understands.
9295
workspace_id: str = ConfigAttribute(env="DATABRICKS_WORKSPACE_ID")
9396

9497
# Cloud provider. When set, is_aws/is_azure/is_gcp use this value directly
@@ -596,7 +599,7 @@ def sql_http_path(self) -> Optional[str]:
596599
if self.cluster_id:
597600
response = requests.get(f"{self.host}/api/2.0/preview/scim/v2/Me", headers=headers)
598601
# get workspace ID from the response header
599-
workspace_id = response.headers.get("x-databricks-org-id")
602+
workspace_id = response.headers.get("x-databricks-workspace-id")
600603
return f"sql/protocolv1/o/{workspace_id}/{self.cluster_id}"
601604
if self.warehouse_id:
602605
return f"/sql/1.0/warehouses/{self.warehouse_id}"

databricks/sdk/mixins/files.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,8 +996,10 @@ def _create_request_builder(self):
996996
def _resolve_workspace_id(self) -> Optional[str]:
997997
"""Resolves the workspace ID by querying the SCIM Me endpoint."""
998998
try:
999-
response = self._api.do("GET", "/api/2.0/preview/scim/v2/Me", response_headers=["X-Databricks-Org-Id"])
1000-
workspace_id = response.get("X-Databricks-Org-Id")
999+
response = self._api.do(
1000+
"GET", "/api/2.0/preview/scim/v2/Me", response_headers=["X-Databricks-Workspace-Id"]
1001+
)
1002+
workspace_id = response.get("X-Databricks-Workspace-Id")
10011003
if workspace_id:
10021004
return str(workspace_id)
10031005
except Exception:

databricks/sdk/mixins/sharing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def list(self, *, max_results: Optional[int] = None, page_token: Optional[str] =
3333
}
3434
cfg = self._api._cfg
3535
if cfg.workspace_id:
36-
headers["X-Databricks-Org-Id"] = cfg.workspace_id
36+
headers["X-Databricks-Workspace-Id"] = cfg.workspace_id
3737

3838
if "max_results" not in query:
3939
query["max_results"] = 0

databricks/sdk/mixins/workspace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def upload(
8888
headers = {}
8989
cfg = self._api._cfg
9090
if cfg.workspace_id:
91-
headers["X-Databricks-Org-Id"] = cfg.workspace_id
91+
headers["X-Databricks-Workspace-Id"] = cfg.workspace_id
9292
try:
9393
return self._api.do(
9494
"POST",
@@ -121,6 +121,6 @@ def download(self, path: str, *, format: Optional[ExportFormat] = None) -> Binar
121121
headers = {}
122122
cfg = self._api._cfg
123123
if cfg.workspace_id:
124-
headers["X-Databricks-Org-Id"] = cfg.workspace_id
124+
headers["X-Databricks-Workspace-Id"] = cfg.workspace_id
125125
response = self._api.do("GET", "/api/2.0/workspace/export", query=query, headers=headers, raw=True)
126126
return response["contents"]

tests/integration/test_unified_profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_spog_workspace_google_credentials(isolated_env):
9090
# google-credentials uses a GCP ID token with target_audience=cfg.host.
9191
# On the unified host this produces the same token for both account and workspace
9292
# requests (identical OIDC exchange, identical audience). Account-level APIs accept
93-
# this token, but workspace-level APIs return 401. The X-Databricks-Org-Id header
93+
# this token, but workspace-level APIs return 401. The X-Databricks-Workspace-Id header
9494
# is set correctly. This appears to be a server-side limitation on unified hosts.
9595
pytest.skip("google-credentials ID token is rejected for workspace operations on unified hosts")
9696
env = isolated_env("ucacct")

tests/test_config.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ def test_oidc_endpoints_falls_back_to_databricks_when_no_azure_client_id(mocker,
453453
assert "https://adb-123.4.azuredatabricks.net/oidc/v1/token" == endpoints.token_endpoint
454454

455455

456-
def test_workspace_org_id_header_on_unified_host(requests_mock):
457-
"""Test that X-Databricks-Org-Id header is added for workspace clients on unified hosts."""
456+
def test_workspace_id_header_on_unified_host(requests_mock):
457+
"""Test that X-Databricks-Workspace-Id header is added for workspace clients on unified hosts."""
458458

459459
requests_mock.get("https://unified.databricks.com/api/2.0/preview/scim/v2/Me", json={"result": "success"})
460460

@@ -468,12 +468,12 @@ def test_workspace_org_id_header_on_unified_host(requests_mock):
468468
workspace_client = WorkspaceClient(config=config)
469469
workspace_client.current_user.me()
470470

471-
# Verify the request was made with the X-Databricks-Org-Id header
472-
assert requests_mock.last_request.headers.get("X-Databricks-Org-Id") == "test-workspace-123"
471+
# Verify the request was made with the X-Databricks-Workspace-Id header
472+
assert requests_mock.last_request.headers.get("X-Databricks-Workspace-Id") == "test-workspace-123"
473473

474474

475-
def test_not_workspace_org_id_header_on_unified_host_on_account_endpoint(requests_mock):
476-
"""Test that X-Databricks-Org-Id header is added for workspace clients on unified hosts."""
475+
def test_not_workspace_id_header_on_unified_host_on_account_endpoint(requests_mock):
476+
"""Test that X-Databricks-Workspace-Id header is added for workspace clients on unified hosts."""
477477

478478
requests_mock.get(
479479
"https://unified.databricks.com/api/2.0/accounts/test-account/scim/v2/Groups/test-group-123",
@@ -490,12 +490,12 @@ def test_not_workspace_org_id_header_on_unified_host_on_account_endpoint(request
490490
account_client = AccountClient(config=config)
491491
account_client.groups.get("test-group-123")
492492

493-
# Verify the request was made without the X-Databricks-Org-Id header
494-
assert "X-Databricks-Org-Id" not in requests_mock.last_request.headers
493+
# Verify the request was made without the X-Databricks-Workspace-Id header
494+
assert "X-Databricks-Workspace-Id" not in requests_mock.last_request.headers
495495

496496

497-
def test_no_org_id_header_on_regular_workspace(requests_mock):
498-
"""Test that X-Databricks-Org-Id header is NOT added for regular workspace hosts."""
497+
def test_no_workspace_id_header_on_regular_workspace(requests_mock):
498+
"""Test that X-Databricks-Workspace-Id header is NOT added for regular workspace hosts."""
499499
from databricks.sdk.core import ApiClient
500500

501501
requests_mock.get("https://test.databricks.com/api/2.0/test", json={"result": "success"})
@@ -505,8 +505,8 @@ def test_no_org_id_header_on_regular_workspace(requests_mock):
505505
api_client = ApiClient(config)
506506
api_client.do("GET", "/api/2.0/test")
507507

508-
# Verify the X-Databricks-Org-Id header was NOT added
509-
assert "X-Databricks-Org-Id" not in requests_mock.last_request.headers
508+
# Verify the X-Databricks-Workspace-Id header was NOT added
509+
assert "X-Databricks-Workspace-Id" not in requests_mock.last_request.headers
510510

511511

512512
def test_disable_oauth_refresh_token_from_env(monkeypatch, mocker):

tests/test_files.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ def match_request_to_response(
926926
resp = requests.Response()
927927
resp.status_code = 200
928928
resp._content = b"{}"
929-
resp.headers["X-Databricks-Org-Id"] = "12345"
929+
resp.headers["X-Databricks-Workspace-Id"] = "12345"
930930
resp.request = request
931931
resp.url = request.url
932932
return resp
@@ -1478,7 +1478,7 @@ def custom_matcher(request: requests.Request) -> Optional[requests.Response]:
14781478
resp = requests.Response()
14791479
resp.status_code = 200
14801480
resp._content = b"{}"
1481-
resp.headers["X-Databricks-Org-Id"] = "12345"
1481+
resp.headers["X-Databricks-Workspace-Id"] = "12345"
14821482
resp.request = request
14831483
resp.url = request.url
14841484
return resp

0 commit comments

Comments
 (0)