From 5554673fd883dd1a2ff065fcba5c545f498ab7e0 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 8 Oct 2025 17:04:59 +0000 Subject: [PATCH 1/3] Add user agent for DBUtils --- databricks/sdk/dbutils.py | 6 +++++- tests/test_dbutils.py | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/databricks/sdk/dbutils.py b/databricks/sdk/dbutils.py index af5ebb821..deb4e5c19 100644 --- a/databricks/sdk/dbutils.py +++ b/databricks/sdk/dbutils.py @@ -210,7 +210,11 @@ def __init__(self) -> None: class RemoteDbUtils: def __init__(self, config: "Config" = None): - self._config = Config() if not config else config + # Create a shallow copy of the config to allow the use of a custom + # user-agent while avoiding modifying the original config. + self._config = Config() if not config else config.copy() + self._config.with_user_agent_extra("sdk-feature", "dbutils") + self._client = ApiClient(self._config) self._clusters = compute_ext.ClustersExt(self._client) self._commands = compute.CommandExecutionAPI(self._client) diff --git a/tests/test_dbutils.py b/tests/test_dbutils.py index 9cd3d32fd..d01608257 100644 --- a/tests/test_dbutils.py +++ b/tests/test_dbutils.py @@ -290,3 +290,12 @@ def test_dbutils_proxy_overrides(dbutils, mocker, restorable_env): return_value="test_cluster_id", ) assert dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get() == "test_source_file" + + +def test_dbutils_adds_user_agent(config): + from databricks.sdk.dbutils import RemoteDbUtils + + # Create dbutils and check that user-agent includes sdk-feature/dbutils + dbutils = RemoteDbUtils(config) + + assert "sdk-feature/dbutils" in dbutils._config.user_agent From d766f1335d1f7fa7262626f66d6c49448f804d36 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 8 Oct 2025 17:06:52 +0000 Subject: [PATCH 2/3] Update kv pair --- databricks/sdk/dbutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/databricks/sdk/dbutils.py b/databricks/sdk/dbutils.py index deb4e5c19..38334d8ec 100644 --- a/databricks/sdk/dbutils.py +++ b/databricks/sdk/dbutils.py @@ -213,7 +213,7 @@ def __init__(self, config: "Config" = None): # Create a shallow copy of the config to allow the use of a custom # user-agent while avoiding modifying the original config. self._config = Config() if not config else config.copy() - self._config.with_user_agent_extra("sdk-feature", "dbutils") + self._config.with_user_agent_extra("dbutils", "remote") self._client = ApiClient(self._config) self._clusters = compute_ext.ClustersExt(self._client) From bfd029a0a1281ee163b8bac3fbc5ed885ec8edf8 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 8 Oct 2025 17:13:56 +0000 Subject: [PATCH 3/3] Make fmt --- databricks/sdk/dbutils.py | 2 +- tests/test_dbutils.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/databricks/sdk/dbutils.py b/databricks/sdk/dbutils.py index 38334d8ec..6deffc0fc 100644 --- a/databricks/sdk/dbutils.py +++ b/databricks/sdk/dbutils.py @@ -210,7 +210,7 @@ def __init__(self) -> None: class RemoteDbUtils: def __init__(self, config: "Config" = None): - # Create a shallow copy of the config to allow the use of a custom + # Create a shallow copy of the config to allow the use of a custom # user-agent while avoiding modifying the original config. self._config = Config() if not config else config.copy() self._config.with_user_agent_extra("dbutils", "remote") diff --git a/tests/test_dbutils.py b/tests/test_dbutils.py index d01608257..638e7e9b2 100644 --- a/tests/test_dbutils.py +++ b/tests/test_dbutils.py @@ -297,5 +297,5 @@ def test_dbutils_adds_user_agent(config): # Create dbutils and check that user-agent includes sdk-feature/dbutils dbutils = RemoteDbUtils(config) - - assert "sdk-feature/dbutils" in dbutils._config.user_agent + + assert "dbutils/remote" in dbutils._config.user_agent