Skip to content

Commit 7e74a3f

Browse files
authored
Fix: use public user_agent_entry connect parameter (#64)
The databricks-sql-connector 4.0.1 release renamed the connect parameter `_user_agent_entry` to `user_agent_entry` and emits a deprecation warning when the old name is passed. Switch the dialect's `do_connect` listener and all call sites to the new name, pop any legacy `_user_agent_entry` callers still supply so it isn't forwarded, and bump the connector floor to >=4.0.1 to guarantee the new key is understood. Fixes #36.
1 parent 3ab18ed commit 7e74a3f

6 files changed

Lines changed: 11 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History
22

3+
# 2.0.10 (unreleased)
4+
5+
- Fix: Use public `user_agent_entry` connect parameter instead of deprecated `_user_agent_entry` to silence the deprecation warning from `databricks-sql-connector >= 4.0.1` (databricks/databricks-sqlalchemy#36)
6+
37
# 2.0.9 (2026-02-20)
48

59
- Feature: Added `pool_pre_ping` support via `do_ping()` override to detect and recycle dead connections (databricks/databricks-sqlalchemy#54 by @msrathore-db)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include = ["CHANGELOG.md"]
1010

1111
[tool.poetry.dependencies]
1212
python = "^3.8.0"
13-
databricks_sql_connector = { version = ">=4.0.0"}
13+
databricks_sql_connector = { version = ">=4.0.1"}
1414
pyarrow = { version = ">=14.0.1"}
1515
sqlalchemy = { version = ">=2.0.21" }
1616

sqlalchemy_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
# See src/databricks/sql/thrift_backend.py for complete list
5454
extra_connect_args = {
5555
"_tls_verify_hostname": True,
56-
"_user_agent_entry": "PySQL Example Script",
56+
"user_agent_entry": "PySQL Example Script",
5757
}
5858

5959

src/databricks/sqlalchemy/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def receive_do_connect(dialect, conn_rec, cargs, cparams):
429429
if not dialect.name == "databricks":
430430
return
431431

432-
ua = cparams.get("_user_agent_entry", "")
432+
ua = cparams.pop("_user_agent_entry", "") or cparams.get("user_agent_entry", "")
433433

434434
def add_sqla_tag_if_not_present(val: str):
435435
if not val:
@@ -443,7 +443,7 @@ def add_sqla_tag_if_not_present(val: str):
443443

444444
return output
445445

446-
cparams["_user_agent_entry"] = add_sqla_tag_if_not_present(ua)
446+
cparams["user_agent_entry"] = add_sqla_tag_if_not_present(ua)
447447

448448
if sqlalchemy.__version__.startswith("1.3"):
449449
# SQLAlchemy 1.3.x fails to parse the http_path, catalog, and schema from our connection string

tests/test_local/e2e/test_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def version_agnostic_connect_arguments(connection_details) -> Tuple[str, dict]:
5555
CATALOG = connection_details["catalog"]
5656
SCHEMA = connection_details["schema"]
5757

58-
ua_connect_args = {"_user_agent_entry": USER_AGENT_TOKEN}
58+
ua_connect_args = {"user_agent_entry": USER_AGENT_TOKEN}
5959

6060
if sqlalchemy_1_3():
6161
conn_string = f"databricks://token:{ACCESS_TOKEN}@{HOST}"
@@ -510,7 +510,7 @@ def engine(self, connection_details: dict):
510510
SCHEMA = connection_details["schema"]
511511

512512
connection_string = f"databricks://token:{ACCESS_TOKEN}@{HOST}?http_path={HTTP_PATH}&catalog={CATALOG}&schema={SCHEMA}"
513-
connect_args = {"_user_agent_entry": USER_AGENT_TOKEN}
513+
connect_args = {"user_agent_entry": USER_AGENT_TOKEN}
514514

515515
engine = create_engine(connection_string, connect_args=connect_args)
516516
return engine

tests/test_local/e2e/test_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def db_engine(self) -> Engine:
1616
CATALOG = self.arguments["catalog"]
1717
SCHEMA = self.arguments["schema"]
1818

19-
connect_args = {"_user_agent_entry": "SQLAlchemy e2e Tests"}
19+
connect_args = {"user_agent_entry": "SQLAlchemy e2e Tests"}
2020

2121
conn_string = f"databricks://token:{ACCESS_TOKEN}@{HOST}?http_path={HTTP_PATH}&catalog={CATALOG}&schema={SCHEMA}"
2222
return create_engine(conn_string, connect_args=connect_args)

0 commit comments

Comments
 (0)