@@ -428,6 +428,97 @@ def fake_session(**kw):
428428 assert captured ["telemetry_circuit_breaker_enabled" ] is False
429429
430430
431+ def test_open_session_omits_phase_7_kwargs_kernel_does_not_accept (monkeypatch ):
432+ """Phase-7 identity/telemetry kwargs must NOT be forwarded to a kernel
433+ ``Session`` whose (fixed, no-``**kwargs``) constructor doesn't declare
434+ them.
435+
436+ The real ``databricks_sql_kernel.Session`` is a PyO3 class with a fixed
437+ signature; the pinned ``^0.2.0`` wheel predates phase 7 and accepts none
438+ of these kwargs, so forwarding them unconditionally raises ``TypeError``
439+ and breaks every ``use_kernel=True`` connection. The other tests here use
440+ a ``**kwargs`` MagicMock that silently swallows the kwargs and hides the
441+ break; this one uses a fixed-signature fake mirroring the real 0.2.0
442+ surface to prove the client gates on what the installed Session supports.
443+ """
444+ captured = {}
445+
446+ # Fixed signature mirroring the pinned 0.2.0 kernel Session: it accepts
447+ # the base connection/tls/retry kwargs but NONE of the phase-7 identity
448+ # or telemetry kwargs, and has no **kwargs catch-all.
449+ def fake_session_v0_2_0 (
450+ host ,
451+ http_path ,
452+ * ,
453+ auth_type = None ,
454+ access_token = None ,
455+ client_id = None ,
456+ client_secret = None ,
457+ oauth_scopes = None ,
458+ token_url = None ,
459+ redirect_port = None ,
460+ oauth_callback_timeout_secs = None ,
461+ tls_ca_cert = None ,
462+ tls_skip_verify = False ,
463+ tls_skip_hostname_verify = False ,
464+ tls_client_cert = None ,
465+ tls_client_key = None ,
466+ retry_min_wait_secs = None ,
467+ retry_max_wait_secs = None ,
468+ retry_max_attempts = None ,
469+ retry_overall_timeout_secs = None ,
470+ http_headers = None ,
471+ catalog = None ,
472+ schema = None ,
473+ session_conf = None ,
474+ complex_types_as_json = False ,
475+ intervals_as_string = False ,
476+ request_timeout_secs = None ,
477+ ):
478+ captured ["host" ] = host
479+ sess = MagicMock ()
480+ sess .session_id = "sess-id"
481+ return sess
482+
483+ monkeypatch .setattr (kernel_client ._kernel , "Session" , fake_session_v0_2_0 )
484+ monkeypatch .setattr (
485+ kernel_client .TelemetryHelper ,
486+ "get_driver_system_configuration" ,
487+ lambda : types .SimpleNamespace (
488+ driver_name = "Databricks SQL Python Connector" ,
489+ driver_version = "1.2.3" ,
490+ runtime_name = "Python 3.12.0" ,
491+ runtime_version = "3.12.0" ,
492+ runtime_vendor = "CPython" ,
493+ os_name = "Linux" ,
494+ os_version = "6.1" ,
495+ os_arch = "x86_64" ,
496+ client_app_name = None ,
497+ locale_name = "en_US" ,
498+ char_set_encoding = "utf-8" ,
499+ ),
500+ )
501+
502+ # The kwargs the client builds must be filtered to what fake_session
503+ # accepts, so open_session succeeds instead of raising TypeError.
504+ kwargs = kernel_client ._kernel_telemetry_kwargs (
505+ {"enable_telemetry" : True , "telemetry_batch_size" : 17 }
506+ )
507+ assert kwargs == {}, f"expected no phase-7 kwargs on 0.2.0 Session, got { kwargs } "
508+
509+ c = kernel_client .KernelDatabricksClient (
510+ server_hostname = "example.cloud.databricks.com" ,
511+ http_path = "/sql/1.0/warehouses/abc" ,
512+ auth_provider = AccessTokenAuthProvider ("dapi-test" ),
513+ ssl_options = None ,
514+ telemetry_options = {"enable_telemetry" : True , "telemetry_batch_size" : 17 },
515+ )
516+ # Would raise TypeError: unexpected keyword argument if the client
517+ # forwarded phase-7 kwargs the fixed-signature Session doesn't declare.
518+ c .open_session (session_configuration = None , catalog = None , schema = None )
519+ assert captured ["host" ] == "example.cloud.databricks.com"
520+
521+
431522def test_execute_command_forwards_parameters_to_bind_param ():
432523 """``execute_command(parameters=[...])`` routes each parameter
433524 through ``bind_tspark_params`` onto the kernel statement before
0 commit comments