Skip to content

Fix empty SQLAlchemy User-Agent tags - #84

Merged
cathleeny merged 1 commit into
mainfrom
fix/sqlalchemy-user-agent-empty-tag
Nov 19, 2026
Merged

cathleeny merged 1 commit into
mainfrom
fix/sqlalchemy-user-agent-empty-tag

Conversation

@cathleeny

Copy link
Copy Markdown
Collaborator

What did you change, and why?

Why: When no custom user_agent_entry is given (missing, empty, or None), the SQLAlchemy connect hook sends sqlalchemy + or sqlalchemy + None as the User-Agent tag instead of sqlalchemy. A second, independent if/else in add_sqla_tag_if_not_present overwrites the empty-entry result.

Change: Make the branches mutually exclusive (if / elif / else), so an empty entry becomes sqlalchemy. Non-empty entries, the existing-tag check, legacy _user_agent_entry precedence, and idempotency across repeated connects are unchanged. This change only fixes the malformed empty-entry tag and does not change how already-tagged values are handled.

How do you know it works?

Testing:

  • Added tests/test_local/test_user_agent.py, with 17 offline cases:
    • missing, empty, and None entries
    • custom and already-tagged entries
    • legacy-key precedence
    • non-Databricks dialects left untouched
    • repeated hook calls
    • the real Engine.connect() event path, stopped at the DBAPI boundary before any network call
  • On Python 3.11 with databricks-sql-connector 4.9.0 and SQLAlchemy 2.1.8:
    • 8 of the new cases fail on unmodified main.
    • All 316 tests in tests/test_local, excluding e2e, pass with the fix.
  • black --check src passes.
  • I did not run the warehouse e2e tests.

This pull request and its description were written by Isaac.

Keep the empty-entry result from being overwritten by the custom-tag branch. Add offline coverage for missing and null tags, legacy arguments, idempotency and engine connection events.

Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>

Co-authored-by: Isaac <no-reply@databricks.com>
@cathleeny
cathleeny merged commit 612fcd2 into main Nov 19, 2026
9 checks passed
@cathleeny
cathleeny deleted the fix/sqlalchemy-user-agent-empty-tag branch November 19, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants