FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(kernel): honor _connection_uri and _port on the use_kernel path by eric-wang-1990 · Pull Request #915 · databricks/databricks-sql-python · GitHub

feat(kernel): honor _connection_uri and _port on the use_kernel path - #915

Open
eric-wang-1990 wants to merge 10 commits into
mainfrom
feat/kernel-honor-connection-uri-port
Open

feat(kernel): honor _connection_uri and _port on the use_kernel path#915
eric-wang-1990 wants to merge 10 commits into
mainfrom
feat/kernel-honor-connection-uri-port

Conversation

Copy link
Copy Markdown
Contributor

What

On use_kernel=True, Session._create_backend forwarded only server_hostname and http_path to KernelDatabricksClient, so _connection_uri and _port were silently ignored — a connection using either reached server_hostname/http_path instead, with no error (a successful connection to the wrong endpoint).

This adds _kernel_host_and_path(), which resolves the (host, http_path) the kernel Session should use:

  • _connection_uri (a full scheme://host[:port]/path URI, mirroring the Thrift backend's direct-URI override) is split into its authority (→ kernel host) and path+query (→ http_path). _connection_uri wins over _port, matching Thrift.
  • _port is otherwise folded into the host authority (host:port), unless the hostname already carries one.
  • No override set → server_hostname/http_path pass through unchanged (common path untouched).

Why no kernel change is needed

Verified against the kernel repo: the kernel Session host accepts a fully-qualified URL, and normalise_host (src/config.rs) only prepends https:// when the scheme is absent and trims a trailing slash — it preserves the scheme and never strips the port. So both overrides are expressible connector-side. (Kernel-genuine transport knobs — socket timeout, connection pool — remain tracked in PECOBLR-4150.)

Tests

TestKernelHostAndPathOverrides in tests/unit/test_session.py — pure-function coverage (no kernel wheel needed) for: URI split (authority/path/query), scheme defaulting, _connection_uri winning over _port, port folding, scheme preservation, and no-double-port.

pytest tests/unit/test_session.py -k "Kernel and (connection_uri or port)"  → 7 passed, 38 deselected
pytest tests/unit/test_session.py                                          → 42 passed, 3 skipped (pyarrow-only kernel tests)

Jira: PECOBLR-4151. Reference doc rows for _port / _connection_uri in #913 should flip to supported-on-kernel once this merges.

This pull request and its description were written by Isaac.


This PR was created with GitHub MCP.

The kernel branch of Session._create_backend forwarded only server_hostname
and http_path, so _connection_uri and _port were silently ignored on
use_kernel=True (connection reached server_hostname/http_path with no error).

Add _kernel_host_and_path(): decompose _connection_uri into the kernel host
(scheme+authority) + http_path, and fold _port into the host authority.
No kernel change needed — the kernel Session host accepts a fully-qualified
https://host:port and its normalise_host preserves scheme and port.

PECOBLR-4151.

Co-authored-by: Isaac
Signed-off-by: eric-wang-1990 <e.wang@databricks.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

This PR fixes use_kernel=True connection override handling so _connection_uri and _port are honored when constructing the kernel backend endpoint, preventing silent connections to an unintended host/path.

Changes:

  • Added _kernel_host_and_path() to resolve (host, http_path) for the kernel backend, honoring _connection_uri and _port.
  • Updated Session._create_backend to pass the resolved host/path to KernelDatabricksClient.
  • Added unit tests covering _connection_uri splitting, query preservation, precedence over _port, and port folding.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
tests/unit/test_session.py Adds unit tests for kernel host/http_path override resolution.
src/databricks/sql/session.py Implements _kernel_host_and_path() and wires it into the kernel backend creation path.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/databricks/sql/session.py Outdated
Comment on lines +47 to +48
# Ensure a scheme so urlsplit populates netloc rather than path; the
# Thrift backend defaults a scheme-less URI to https, so do the same.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Reworded the misleading inline comment in _kernel_host_and_path (session.py:47-49). The reviewer correctly noted that the Thrift backend passes _connection_uri through unmodified (uri = kwargs.get("_connection_uri")) rather than defaulting a scheme-less URI to https — that defaulting only applies to the server_hostname/http_path-built URI in the elif branch. The comment now justifies the https default on connector-transport-default grounds instead of a nonexistent Thrift behavior. Comment-only edit; no logic or tests affected.

Pushed a5e0a08 (bundled with 4 other thread(s)).

Comment thread src/databricks/sql/session.py Outdated
Comment on lines +50 to +52
parts = urlsplit(uri)
host = "{}://{}".format(parts.scheme, parts.netloc)
path = parts.path or http_path

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Resolved with a code change. _kernel_host_and_path now raises a clear ValueError when _connection_uri has no host authority, and I added a test covering the malformed cases the reviewer flagged.

Pushed a5e0a08 (bundled with 4 other thread(s)).

Comment thread src/databricks/sql/session.py Outdated
Comment on lines +59 to +69
# Split off any scheme so we can inspect the authority; the kernel
# re-adds https:// when it is absent. Only append the port when the
# authority does not already carry one.
scheme_match = re.match(r"^(https?://)(.*)$", server_hostname)
scheme = scheme_match.group(1) if scheme_match else ""
authority = (scheme_match.group(2) if scheme_match else server_hostname).rstrip(
"/"
)
if ":" not in authority:
authority = "{}:{}".format(authority, port)
return "{}{}".format(scheme, authority), http_path

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed as the reviewer suggested. Summary:

  • src/databricks/sql/session.py: In the _port branch of _kernel_host_and_path, swapped the ":" not in host heuristic for urlsplit(probe).port is None. IPv6 authorities contain : even with no port (e.g. [::1]), so the old check wrongly skipped appending _port. Since urlsplit only populates port when a scheme is present, a temporary https:// is prepended for scheme-less hosts before probing.
  • tests/unit/test_session.py: Added two regression tests — [::1] gets :8443 appended, and [::1]:7000 is left untouched.

Tests pass (46 passed, realkernel deselected).

Pushed a5e0a08 (bundled with 4 other thread(s)).

peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Verdict: 1 Low

Looks good — the new _kernel_host_and_path faithfully mirrors the Thrift backend's _connection_uri/_port handling (thrift_backend.py:155-162), is a pure function with solid unit coverage, and leaves the common (no-override) path untouched. One low-severity edge case: SPOG org-id headers are derived from the original http_path, not the _connection_uri-resolved one.

server_hostname reaches the backend as a bare host on this path, so drop
the defensive scheme peel/re-add: just append the port when the host has
none, and let the kernel's normalise_host add the scheme. Removes the
now-moot scheme-preservation test.

Co-authored-by: Isaac
Signed-off-by: eric-wang-1990 <e.wang@databricks.com>

peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Verdict: 1 Low

Looks good — the connector-side remap in _kernel_host_and_path correctly mirrors the Thrift backend's _connection_uri/_port precedence (verified against thrift_backend.py:154-162), and the _port is not None check (no 443 default) correctly folds only an explicit port. One low-severity coverage gap: the pure-function tests don't guard the _create_backend → KernelDatabricksClient wiring that this PR actually fixes.

eric-wang-1990 added the engineer-bot Maintainer-applied gate: triggers engineer-bot (bug-fix on issue / take-over on PR). label Aug 18, 2026
Addresses:
  - #3800053148 at src/databricks/sql/session.py:48
  - #3800053178 at src/databricks/sql/session.py:52
  - #3800053209 at src/databricks/sql/session.py:69
  - #3800056285 at src/databricks/sql/session.py:245
  - #3800209433 at src/databricks/sql/session.py:245

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Verdict: 1 Medium

Solid, well-tested change that correctly maps _connection_uri/_port onto the kernel host/path. One medium gap: the SPOG-header re-derivation guard (and self._spog_headers) is asymmetric — it won't inject x-databricks-org-id when the original path lacked workspace info but a _connection_uri override introduces one, leaving that direction of mis-routing unfixed and untested.

Comment thread src/databricks/sql/session.py Outdated

peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Verdict: 1 Low

Solid, well-tested change — the _connection_uri/_port resolution, IPv6-aware port detection, and bidirectional SPOG org-id re-derivation are all correct and covered by pure-function and integration tests. One low-severity latent crash: a path-less, query-bearing _connection_uri combined with http_path=None dereferences None.split(...).

Comment thread src/databricks/sql/session.py Outdated
Addresses:
  - #3802164062 at src/databricks/sql/session.py:71

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Verdict: 1 Low

Looks good — solid, thoroughly-tested change; one low-severity type-hint accuracy note. The _connection_uri/_port resolution correctly mirrors Thrift precedence, the SPOG org-id header is re-derived in both directions when the resolved path changes, caller-set headers are preserved, and edge cases (IPv6 literals, double-query, scheme defaulting, missing authority) are covered by pure-function and integration tests.

Addresses:
  - #3802212055 at src/databricks/sql/session.py:24

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Verdict: 1 Low

Looks good — a focused, well-tested fix that honors _connection_uri/_port on the kernel path. The _kernel_host_and_path URI split, port folding (incl. IPv6 handling), and the SPOG org-id header re-derivation from the resolved path (both directions, caller-header precedence preserved) are all correct and covered by pure-function + integration tests. One low-severity robustness note filed inline about an opaque ValueError on malformed server_hostname ports.

Comment thread src/databricks/sql/session.py Outdated
Addresses:
  - #3802255225 at src/databricks/sql/session.py:93

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Verdict: 1 Low

Looks good overall — the _connection_uri/_port resolution and the SPOG org-id re-derivation are carefully reasoned and thoroughly unit-tested (pure-function + kernel-client-threading + header-re-derivation cases). One low-severity edge case: a _connection_uri with a bare trailing slash silently discards the original warehouse path.

Comment thread src/databricks/sql/session.py Outdated
Addresses:
  - #3802314928 at src/databricks/sql/session.py:71

Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>

peco-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

✅ No issues identified by the review bot.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted engineer-bot Maintainer-applied gate: triggers engineer-bot (bug-fix on issue / take-over on PR).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL