mssql_python: discrete connection fields are silently ignored when connection_string is set
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
Research direction
Start in sqlspec/adapters/mssql_python/core.py at build_connection_config, then compare the mssql_python behavior with the arrow_odbc adapter's connection configuration logic and documented precedence. Use the reproduction in the issue to verify that database overrides are no longer silently ignored, and add or update coverage for the chosen conflict behavior.
Written by the indexing model from the issue text.
Description
Summary
In the mssql_python adapter, build_connection_config returns early when connection_string is present, so every discrete field in the same connection_config (server, database, uid, pwd, encrypt, extra, ...) is dropped without a warning or error.
# sqlspec/adapters/mssql_python/core.py
connection_string = config.pop("connection_string", None)
if connection_string is not None:
return str(connection_string), connect_kwargs
Why it matters
A common pattern is to hold one base config and derive per-database configs from it by overriding database:
base = {"connection_string": "Server=host,1433;UID=app;PWD=...;Encrypt=yes;"}
per_db = MssqlPythonConfig(connection_config={**base, "database": "sales"})
per_db connects to the login's default database, not sales. Nothing fails — queries simply run against the wrong database, which is hard to notice when iterating over several databases on one instance.
Reproduction
from sqlspec.adapters.mssql_python.core import build_connection_config
conn_str, _ = build_connection_config(
{"connection_string": "Server=host;UID=u;PWD=p;", "database": "sales"}
)
assert "sales" in conn_str # fails: "Server=host;UID=u;PWD=p;"
Expected
Either of these would remove the silent wrong answer:
- Merge discrete fields with the explicit string, with a documented precedence. The
arrow_odbcadapter already does this (itsbuild_connection_configcomposes the discrete fields and appendsconnection_stringas a suffix, with the precedence described in the docstring), so the two ODBC-style adapters would behave the same way. - Raise a
ValueError(orImproperConfigurationError) whenconnection_stringis combined with any connection-string-level field, naming the conflicting keys.
Option 1 seems the friendlier of the two, provided the precedence is stated (an explicit field overriding the same key inside the string is the least surprising for the per-database case above).
Version
sqlspec 0.63.1; still present on main.
- Dominant language
- Python
- Stars
- 102
- Forks
- 9
- Avg merge
- 8h 38m
- Merged PRs (30d)
- 64
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from litestar-org/sqlspec
-
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
litestar-org/sqlspec#816 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
litestar-org/sqlspec#815 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 45/100
litestar-org/sqlspec#810 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
litestar-org/sqlspec#728 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
litestar-org/sqlspec#509 ·
Maintainers usually reply within 1 day
All issues in litestar-org/sqlspec
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
gradio-app/gradio#13895 ·
Maintainers usually reply within 1 day
-
build-error
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
spack/spack-packages#6713 ·
Maintainers usually reply within 1 day
-
Use issue templates Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ActivityWatch/activitywatch#1464 · 1 reaction ·
Maintainers usually reply within 1 day
-
[Bug]: The ckg tool drops the return type of every decorated Python method in class search results Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
bytedance/trae-agent#483 ·
Maintainers usually reply within 1 day