Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

mssql_python: discrete connection fields are silently ignored when connection_string is set

Open
#788 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
database

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:

  1. Merge discrete fields with the explicit string, with a documented precedence. The arrow_odbc adapter already does this (its build_connection_config composes the discrete fields and appends connection_string as a suffix, with the precedence described in the docstring), so the two ODBC-style adapters would behave the same way.
  2. Raise a ValueError (or ImproperConfigurationError) when connection_string is 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from litestar-org/sqlspec

All issues in litestar-org/sqlspec

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.