Skip to content

Fix a real crash bug in MSSQL JSON handling, correct stale docs - #15

Merged
aersam merged 1 commit into
mainfrom
worktree-mssql-backend
Jul 27, 2026
Merged

Fix a real crash bug in MSSQL JSON handling, correct stale docs#15
aersam merged 1 commit into
mainfrom
worktree-mssql-backend

Conversation

@aersam

@aersam aersam commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

No description provided.

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
@aersam
aersam merged commit 608aa96 into main Jul 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant