Fix SQLAlchemy Entra authentication with connection pools - #48383
Fix SQLAlchemy Entra authentication with connection pools#48383pabloacan wants to merge 2 commits into
Conversation
|
Thank you for your contribution @pabloacan! We will review the pull request and get back to you soon. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). 8 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
Fixes pooled SQLAlchemy Entra authentication by preserving persistent connection parameters and resolving fresh credentials per physical connection.
Changes:
- Copies connection parameters before removing helper-only credentials.
- Returns DBAPI connections using per-connection Entra credentials.
- Adds sync/async regression tests and a changelog entry.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
azure_postgresql_auth/sqlalchemy/entra_connection.py |
Fixes synchronous pooled connections. |
azure_postgresql_auth/sqlalchemy/async_entra_connection.py |
Applies the fix to async engines. |
tests/test_sqlalchemy.py |
Adds synchronous regression coverage. |
tests/test_sqlalchemy_async.py |
Adds asynchronous regression coverage. |
CHANGELOG.md |
Documents the bug fix. |
|
@microsoft-github-policy-service agree company="Industria de Diseño Textil, S.A." |
[Pilot] PR Pipeline Failure AnalysisA CI pipeline failed on this pull request. Here is an automated analysis of what went wrong and how to get the build green. What failedThe pylint validation step for
Recommended next steps
Raw pipeline analysis (azsdk ci analyze)
|
Description
Fixes #48382.
enable_entra_authenticationandenable_entra_authentication_asyncregistered ado_connectlistener that modified SQLAlchemy's persistentconnect_argsdictionary in place:credentialwas removed before the DBAPI connection was created.passwordafter the first physical connection.When a connection pool later created another physical connection, the listener no longer had a
TokenCredentialand raisedCredentialValueError. If it had proceeded, it could also have reused an expired access token.This change copies
cparamsfor eachdo_connectevent, removes the helper-onlycredentialfrom that per-connection copy, resolves Entra credentials there, and returnsdialect.connect(...). The pool's original connection configuration remains unchanged, so every physical connection receives a fresh token resolution.The same behavior is applied to both synchronous and asynchronous SQLAlchemy integrations.
Tests
Added regression coverage for two consecutive physical connection attempts in both sync and async SQLAlchemy integrations.
Updated existing tests to assert that
credentialremains present in the original parameters whiledialect.connectreceives only DBAPI-supported arguments.Ran:
The skipped tests require a live PostgreSQL instance.
Changelog
Added an Unreleased bug-fix entry for SQLAlchemy connection pools using Entra authentication.