File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -266,10 +266,16 @@ def _create_backend(
266266 # different workspace (a different ``?o=`` or cluster path), so
267267 # re-derive the routing header from the resolved path and swap it
268268 # in — otherwise the kernel would receive an org-id that points at
269- # the pre-override workspace (a silent mis-routing). A caller-set
270- # header still wins: ``_spog_headers`` is empty in that case, so the
271- # explicit header is left untouched below.
272- if kernel_http_path != http_path and self ._spog_headers :
269+ # the pre-override workspace (a silent mis-routing). This must fire
270+ # whenever the path changed, in *both* directions: when the original
271+ # path carried routing and the override drops or changes it, and
272+ # when the original had none but the override introduces one — the
273+ # latter is skipped if we also gate on ``self._spog_headers``. Any
274+ # stale extracted header is stripped first, then re-derived; when
275+ # ``_spog_headers`` is empty the filter strips nothing. A caller-set
276+ # header still wins because ``_extract_spog_headers`` re-checks the
277+ # existing headers and returns ``{}`` in that case.
278+ if kernel_http_path != http_path :
273279 base_headers = [
274280 h for h in all_headers if h not in self ._spog_headers .items ()
275281 ]
Original file line number Diff line number Diff line change @@ -639,6 +639,20 @@ def test_org_id_dropped_when_override_has_no_workspace(self):
639639 )
640640 assert "x-databricks-org-id" not in headers
641641
642+ def test_org_id_added_when_override_introduces_workspace (self ):
643+ # The original path carries no workspace routing (so no org-id header is
644+ # set in __init__), but the _connection_uri override introduces one —
645+ # the kernel must see org-id 222 rather than falling back to default
646+ # routing. This exercises the none -> o=222 direction, which is skipped
647+ # if re-derivation is gated on the original path having had a header.
648+ headers = self ._connect_and_get_kernel_headers (
649+ {
650+ "http_path" : "/sql/1.0/warehouses/abc" ,
651+ "_connection_uri" : "https://direct.example.com/sql/1.0/warehouses/xyz?o=222" ,
652+ }
653+ )
654+ assert headers .get ("x-databricks-org-id" ) == "222"
655+
642656 def test_org_id_preserved_when_no_override (self ):
643657 headers = self ._connect_and_get_kernel_headers (
644658 {"http_path" : "/sql/1.0/warehouses/abc?o=111" }
You can’t perform that action at this time.
0 commit comments