From 0c2412b416a07a28c71938378008544078514233 Mon Sep 17 00:00:00 2001 From: Sohail Iqrar Date: Sun, 30 Aug 2026 10:53:01 +0530 Subject: [PATCH] Fix DatabricksSqlHook deprecation warning on every connection databricks-sql-connector deprecated the ``_user_agent_entry`` keyword argument in favour of ``user_agent_entry`` (no leading underscore). Passing the old name logs a warning on every call to get_conn(), which fires for every DatabricksSqlOperator / sensor execution. Switch to the current parameter name so the warning is no longer emitted. --- providers/databricks/docs/changelog.rst | 1 + .../databricks/hooks/databricks_sql.py | 2 +- .../databricks/hooks/test_databricks_sql.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/providers/databricks/docs/changelog.rst b/providers/databricks/docs/changelog.rst index 5f6fbc15ee145..651879497a055 100644 --- a/providers/databricks/docs/changelog.rst +++ b/providers/databricks/docs/changelog.rst @@ -39,6 +39,7 @@ Features Bug Fixes ~~~~~~~~~ +* ``Fix DatabricksSqlHook.get_conn() deprecation warning by passing user_agent_entry without leading underscore (#72102)`` * ``Make 'durable' reach 'default_args' and warn when set below Airflow 3.3 (#71531)`` Doc-only diff --git a/providers/databricks/src/airflow/providers/databricks/hooks/databricks_sql.py b/providers/databricks/src/airflow/providers/databricks/hooks/databricks_sql.py index b13100330d32f..24be7acc92733 100644 --- a/providers/databricks/src/airflow/providers/databricks/hooks/databricks_sql.py +++ b/providers/databricks/src/airflow/providers/databricks/hooks/databricks_sql.py @@ -241,7 +241,7 @@ def get_conn(self) -> AirflowConnection: "catalog": self.catalog, "session_configuration": session_config or None, "http_headers": self.http_headers, - "_user_agent_entry": self.user_agent_value, + "user_agent_entry": self.user_agent_value, **self._get_extra_config(), **self.additional_params, } diff --git a/providers/databricks/tests/unit/databricks/hooks/test_databricks_sql.py b/providers/databricks/tests/unit/databricks/hooks/test_databricks_sql.py index 4d736014efd36..2a018faff87fe 100644 --- a/providers/databricks/tests/unit/databricks/hooks/test_databricks_sql.py +++ b/providers/databricks/tests/unit/databricks/hooks/test_databricks_sql.py @@ -931,6 +931,23 @@ def test_get_conn_does_not_leak_proxies_into_connector(mock_connect, mock_get_re assert "proxies" not in mock_connect.call_args.kwargs +@mock.patch("airflow.providers.databricks.hooks.databricks_sql.sql.connect") +def test_get_conn_passes_user_agent_entry_without_underscore(mock_connect, mock_get_requests): + """get_conn() must pass ``user_agent_entry`` (no leading underscore) to sql.connect(). + + databricks-sql-connector deprecated the ``_user_agent_entry`` alias and logs a warning + on every connection when the old name is used. + """ + hook = DatabricksSqlHook(databricks_conn_id=DEFAULT_CONN_ID, http_path=HTTP_PATH) + + hook.get_conn() + + mock_connect.assert_called_once() + call_kwargs = mock_connect.call_args.kwargs + assert "user_agent_entry" in call_kwargs + assert "_user_agent_entry" not in call_kwargs + + class TestFormatQueryTags: def test_simple_values(self): result = _format_query_tags({"dag_id": "my_dag", "task_id": "my_task"})