Skip to content

Commit 4b29999

Browse files
cathleenyIsaac
andcommitted
fix(kernel): raise NotSupportedError for _port on a kernel without port
A kernel wheel whose Session does not declare `port` rejected the kwarg with a TypeError. Gate it like the other optional kwargs so the error names the fix. Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com> Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 65679c4 commit 4b29999

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎src/databricks/sql/backend/kernel/client.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,14 @@ def open_session(
491491
self._enable_geospatial_support
492492
)
493493
# The kernel validates the port and applies it to the host; unset sends nothing.
494-
port_kwargs = {} if self._port is None else {"port": self._port}
494+
port_kwargs: Dict[str, Any] = {}
495+
if self._port is not None:
496+
if not _kernel_session_accepts_kwarg("port"):
497+
raise NotSupportedError(
498+
"_port requires a newer databricks-sql-kernel wheel "
499+
"that accepts a connection port."
500+
)
501+
port_kwargs["port"] = self._port
495502
max_connections_kwargs: Dict[str, Any] = {}
496503
if _kernel_session_accepts_kwarg("max_connections"):
497504
max_connections_kwargs["max_connections"] = self._max_connections

‎tests/unit/test_kernel_client.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,25 @@ def fake_session(**kw):
586586
assert captured["host"] == "example.cloud.databricks.com"
587587

588588

589+
def test_open_session_port_on_a_kernel_without_port_raises_not_supported(
590+
monkeypatch,
591+
):
592+
def fake_session_without_port(host, http_path, *, enable_geospatial_support=False):
593+
raise AssertionError("must not construct a session")
594+
595+
monkeypatch.setattr(kernel_client._kernel, "Session", fake_session_without_port)
596+
c = kernel_client.KernelDatabricksClient(
597+
server_hostname="example.cloud.databricks.com",
598+
http_path="/sql/1.0/warehouses/abc",
599+
auth_provider=AccessTokenAuthProvider("dapi-test"),
600+
ssl_options=None,
601+
port=8443,
602+
)
603+
604+
with pytest.raises(NotSupportedError, match="newer databricks-sql-kernel"):
605+
c.open_session(session_configuration=None, catalog=None, schema=None)
606+
607+
589608
def test_open_session_passes_phase_7_telemetry_kwargs_to_kernel(monkeypatch):
590609
"""Kernel telemetry phase 7 added binding/runtime identity and
591610
telemetry config kwargs to ``databricks_sql_kernel.Session``."""

0 commit comments

Comments
 (0)