Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Security

### Bug Fixes
* Add `X-Databricks-Org-Id` header to hand-written extension methods (`Workspace.upload()`, `Workspace.download()`, `Shares.list()`, `ServingEndpoints.http_request()`) for SPOG host compatibility.

### Documentation

Expand Down
6 changes: 5 additions & 1 deletion databricks/sdk/mixins/open_ai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ def http_request(
# This is a temporary fix to get the headers we need for the MCP session id
# TODO: Remove this once we have a better way to get back the response headers
headers_to_capture = ["mcp-session-id"]
request_headers = {"Accept": "text/plain", "Content-Type": "application/json"}
cfg = self._api._cfg
if cfg.workspace_id:
request_headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do(
"POST",
"/api/2.0/external-function",
Expand All @@ -181,7 +185,7 @@ def http_request(
"json": js.dumps(json) if json is not None else None,
"params": js.dumps(params) if params is not None else None,
},
headers={"Accept": "text/plain", "Content-Type": "application/json"},
headers=request_headers,
raw=True,
response_headers=headers_to_capture,
)
Expand Down
3 changes: 3 additions & 0 deletions databricks/sdk/mixins/sharing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def list(self, *, max_results: Optional[int] = None, page_token: Optional[str] =
headers = {
"Accept": "application/json",
}
cfg = self._api._cfg
if cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id

if "max_results" not in query:
query["max_results"] = 0
Expand Down
11 changes: 10 additions & 1 deletion databricks/sdk/mixins/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@ def upload(
data["language"] = language.value
if overwrite:
data["overwrite"] = "true"
headers = {}
cfg = self._api._cfg
if cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
try:
return self._api.do(
"POST",
"/api/2.0/workspace/import",
headers=headers,
files={"content": content},
data=data,
)
Expand All @@ -113,5 +118,9 @@ def download(self, path: str, *, format: Optional[ExportFormat] = None) -> Binar
query = {"path": path, "direct_download": "true"}
if format:
query["format"] = format.value
response = self._api.do("GET", "/api/2.0/workspace/export", query=query, raw=True)
headers = {}
cfg = self._api._cfg
if cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
response = self._api.do("GET", "/api/2.0/workspace/export", query=query, headers=headers, raw=True)
return response["contents"]
Loading