@@ -519,6 +519,57 @@ def fake_session_v0_2_0(
519519 assert captured ["host" ] == "example.cloud.databricks.com"
520520
521521
522+ def test_kernel_session_accepts_kwarg_falls_closed_when_not_introspectable (monkeypatch ):
523+ """When ``inspect.signature(_kernel.Session)`` raises (a PyO3 class built
524+ without ``#[pyo3(signature=...)]`` exposes no ``__text_signature__``, so
525+ ``inspect.signature`` raises ``ValueError``), the gate must fall
526+ **closed** and omit every phase-7 kwarg.
527+
528+ Forwarding a kwarg the installed ``Session`` doesn't declare is a hard
529+ ``TypeError`` at construction that breaks every ``use_kernel=True``
530+ connection; omitting one it would have accepted only loses telemetry
531+ richness. The fixed-signature fake in the sibling test always introspects,
532+ so this test uses a stand-in whose signature genuinely can't be read to
533+ cover the real non-introspectable PyO3 binding.
534+ """
535+
536+ class NonIntrospectableSession :
537+ # Mirrors a PyO3 class with no exposed __text_signature__:
538+ # inspect.signature() raises ValueError on it.
539+ def __init__ (self , * args , ** kwargs ): # pragma: no cover - never called
540+ pass
541+
542+ def raise_value_error (_obj ):
543+ raise ValueError ("no signature found for builtin type" )
544+
545+ monkeypatch .setattr (kernel_client ._kernel , "Session" , NonIntrospectableSession )
546+ monkeypatch .setattr (kernel_client .inspect , "signature" , raise_value_error )
547+
548+ assert kernel_client ._kernel_session_accepts_kwarg ("driver_name" ) is False
549+
550+ monkeypatch .setattr (
551+ kernel_client .TelemetryHelper ,
552+ "get_driver_system_configuration" ,
553+ lambda : types .SimpleNamespace (
554+ driver_name = "Databricks SQL Python Connector" ,
555+ driver_version = "1.2.3" ,
556+ runtime_name = "Python 3.12.0" ,
557+ runtime_version = "3.12.0" ,
558+ runtime_vendor = "CPython" ,
559+ os_name = "Linux" ,
560+ os_version = "6.1" ,
561+ os_arch = "x86_64" ,
562+ client_app_name = None ,
563+ locale_name = "en_US" ,
564+ char_set_encoding = "utf-8" ,
565+ ),
566+ )
567+ kwargs = kernel_client ._kernel_telemetry_kwargs (
568+ {"enable_telemetry" : True , "telemetry_batch_size" : 17 }
569+ )
570+ assert kwargs == {}, f"expected no phase-7 kwargs when signature unreadable, got { kwargs } "
571+
572+
522573def test_execute_command_forwards_parameters_to_bind_param ():
523574 """``execute_command(parameters=[...])`` routes each parameter
524575 through ``bind_tspark_params`` onto the kernel statement before
0 commit comments