Repository navigation
Add mssql-python as an optional DBAPI driver for MsSqlHook - #74539
Open
RehanAhmad25 wants to merge 2 commits into
Open
RehanAhmad25 wants to merge 2 commits into
RehanAhmad25 wants to merge 2 commits into
Conversation
1 of 2 tasks
RehanAhmad25
force-pushed
the
feature/74432-mssql-python-driver
branch
from
October 11, 2026 03:42
bce8d0d to
dc2a3b0
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes: #74432
What
MsSqlHookcan now connect with Microsoft'smssql-pythondriver instead ofpymssql. The driver is chosen with a newdbapi_driverconnection extra (pymssqlormssql_python, case-insensitive).pymssqlstays the default, so existing connections behave exactly as before. An unsupported value raises aValueError.How it works
With
dbapi_driverset tomssql_python:get_conn()builds the connection withmssql_python.connect(...). The host and port are sent asServer=host,port, and the schema, login and password map toDatabase,UIDandPWD.Encrypt,TrustServerCertificate,Authentication) are passed to the driver as keyword arguments. The hook's own extras (dbapi_driver,sqlalchemy_scheme,placeholderand the otherDbApiHookformat extras) are not passed on, and empty values are dropped.mssql+mssqlpython.sqlalchemy_schemestill overrides it.get_uri()stripsdbapi_driverfrom the query string.?, because mssql-python does not accept a plain%s. Theplaceholderextra still overrides it.Rowobjects.autocommitproperty.mssql-pythonextra.pymssqlis now imported inside the pymssql code path, not at module level. It is still a required dependency of the provider. Making it optional would be a separate change.Where
providers/microsoft/mssql/src/airflow/providers/microsoft/mssql/hooks/mssql.py: the hook changesproviders/microsoft/mssql/tests/unit/microsoft/mssql/hooks/test_mssql.py: new testsproviders/microsoft/mssql/docs/connections/mssql.rst: new "Choosing the DBAPI driver" sectionproviders/microsoft/mssql/pyproject.toml: new optional extramssql-python(mssql-python>=1.15.0)providers/microsoft/mssql/docs/index.rst: extras table, updated by the repo's hookuv.lock: regenerated withuv 0.13.0for the new extra (addsmssql-pythonandmssql-python-odbc)Notes for reviewers
>=1.15.0as the floor because it is the version I checked the driver's behaviour against. Happy to loosen it if you prefer.Testing
I added 14 new test cases for driver selection and validation, scheme and placeholder defaults,
get_uri, the arguments passed toconnect, the missing-package error, autocommit and row conversion. The existing pymssql tests pass unchanged (35 passed in Breeze). The prek hooks, including ruff, mypy for providers and the provider.yaml check, pass locally.Both drivers are mocked in the tests, so I have not run this against a real SQL Server yet. The Microsoft Entra ID
Authenticationoptions in particular are untested, so a check on a real instance would be welcome.Related: #72000
Was generative AI tooling used to co-author this PR?
Generated-by: Claude (Anthropic) following the guidelines