Fix a real crash bug in MSSQL JSON handling, correct stale docs - #15
Merged
Conversation
Investigated whether/how we support SQL Server's native `json` type
(current Azure SQL/SQL Server 2025+, distinct from the older
NVARCHAR(MAX)-plus-OPENJSON() convention). Confirmed via source and binary
inspection of the installed mssql-python 1.12.0 driver: it has zero special
handling for `json` -- no distinct ODBC type code, fetched as plain str,
and critically, binding a raw Python dict/list parameter raises
TypeError ("Unsupported parameter type"). Our mssql_crud.py write path did
no serialization before binding, so any caller passing a dict/list value
for a JSON-ish column would have hit that crash outright.
- New db/mssql_sql.json_encode_value()/json_encode_values(): serialize
dict/list values to JSON text before binding. Wired into every mssql_*
write path (insert, insert_many, update_dict, upsert_dict,
upsert_many_dict). Deduplicated testdb/mssql/api.py's _insert_test_data,
which already had its own inline version of this same logic, to use the
shared helper.
- No read-side auto-parsing: the driver can't tell us which columns are
json-typed (same opaque str as any other text column), so values come
back as raw JSON text: callers deserialize with json.loads() themselves.
- Corrected README's stale "MSSQL has no ... first-class JSONB column type"
framing -- current Azure SQL/SQL Server does have a native json type now
(parses/introspects/diffs like any other column type); documented the
actual write-serialize/no-read-parse behavior instead.
- Added a live NVARCHAR(MAX)-JSON round-trip test (the CI container image
is SQL Server 2022, which predates the native json type, but the
write-side driver behavior being fixed is identical either way) plus
offline tests for the new helper and its CRUD wiring.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RLWLqcTyNJ1ncZvJ5rn6Xy
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.
No description provided.