Skip to content

Commit 80a6dd9

Browse files
ai: apply changes for #915 (1 review thread)
Addresses: - #3802045805 at src/databricks/sql/session.py:62 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
1 parent 043df78 commit 80a6dd9

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/databricks/sql/session.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ def _kernel_host_and_path(
3636
the Thrift backend's direct-URI override) is split into its authority
3737
(returned as ``host``) and its path+query (returned as ``http_path``).
3838
``_connection_uri`` wins over ``_port``, matching the Thrift backend.
39+
When the URI omits a path (e.g. ``https://host:8443`` or
40+
``https://host:8443?o=222``) the connection's original ``http_path`` is
41+
retained, and any query on the URI is applied to that retained path — so
42+
a path-less, query-bearing URI overrides only the host and query while
43+
keeping the original warehouse path. The fragment (``#...``) is dropped
44+
since it never goes on the wire.
3945
- ``_port`` is otherwise folded into the host authority, unless the
4046
hostname already carries a port.
4147
@@ -58,6 +64,9 @@ def _kernel_host_and_path(
5864
"authority (expected scheme://host[:port]/path)".format(connection_uri)
5965
)
6066
host = "{}://{}".format(parts.scheme, parts.netloc)
67+
# A path-less URI keeps the connection's original http_path; any query
68+
# on the URI is then applied to that retained path (host + query
69+
# override, path preserved). See the docstring for the rationale.
6170
path = parts.path or http_path
6271
if parts.query:
6372
path = "{}?{}".format(path, parts.query)

tests/unit/test_session.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,24 @@ def test_connection_uri_preserves_query(self):
762762
assert host == "https://h.example.com"
763763
assert path == "/sql/1.0/warehouses/xyz?o=123"
764764

765+
def test_connection_uri_without_path_retains_original_path(self):
766+
# A path-less URI overrides only the host; the connection's original
767+
# http_path is retained.
768+
host, path = _kernel_host_and_path(
769+
self.HOST, self.PATH, {"_connection_uri": "https://h.example.com:8443"}
770+
)
771+
assert host == "https://h.example.com:8443"
772+
assert path == self.PATH
773+
774+
def test_connection_uri_without_path_applies_query_to_retained_path(self):
775+
# A path-less, query-bearing URI overrides the host and applies the
776+
# query to the retained original path (documented fallback semantics).
777+
host, path = _kernel_host_and_path(
778+
self.HOST, self.PATH, {"_connection_uri": "https://h.example.com:8443?o=222"}
779+
)
780+
assert host == "https://h.example.com:8443"
781+
assert path == "{}?o=222".format(self.PATH)
782+
765783
def test_connection_uri_wins_over_port(self):
766784
host, path = _kernel_host_and_path(
767785
self.HOST,

0 commit comments

Comments
 (0)