Skip to content

fix: decode nested msgspec rename fields - #680

Merged
cofin merged 1 commit into
mainfrom
fix/query-findings
Aug 6, 2026
Merged

fix: decode nested msgspec rename fields#680
cofin merged 1 commit into
mainfrom
fix/query-findings

Conversation

@cofin

@cofin cofin commented Aug 6, 2026

Copy link
Copy Markdown
Member

Closes #679

Summary

  • replace root-level msgspec rename inference with cached, type-aware input normalization based on exact Struct field encode names
  • normalize nested Structs through declared optional, annotated, collection, tuple, and mapping types without rewriting arbitrary mapping keys
  • preserve encoded aliases, prefer encoded keys when both aliases are present, and leave unknown fields and ambiguous unions to msgspec validation
  • add regression coverage for single records, batches, mixed rename conventions, callable and explicit aliases, nested optionals and collections, duplicate aliases, arbitrary mappings, and strict unknown-field handling

Root cause

The conversion path inferred one rename convention from the outer Struct and recursively applied it to every nested dictionary. Single-word outer fields did not reveal the configured convention, while mixed nested conventions and arbitrary dictionary payloads could not be represented safely by one global transform.

@cofin cofin changed the title fix(#679): decode nested msgspec rename fields fix: decode nested msgspec rename fields Aug 6, 2026
@cofin
cofin marked this pull request as ready for review August 6, 2026 16:15
@codecov-commenter

codecov-commenter commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.73239% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.38%. Comparing base (b6b946a) to head (376a2f1).

Files with missing lines Patch % Lines
sqlspec/utils/schema.py 88.73% 6 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #680      +/-   ##
==========================================
+ Coverage   77.32%   77.38%   +0.05%     
==========================================
  Files         476      476              
  Lines       68107    68163      +56     
  Branches     9363     9376      +13     
==========================================
+ Hits        52665    52746      +81     
- Misses      12033    12035       +2     
+ Partials     3409     3382      -27     
Flag Coverage Δ
py3.10 75.66% <88.73%> (+0.01%) ⬆️
py3.12 75.67% <88.73%> (+0.01%) ⬆️
py3.13 75.67% <88.73%> (+0.01%) ⬆️
py3.14 76.55% <88.73%> (+0.01%) ⬆️
unit 64.92% <88.73%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sqlspec/utils/schema.py 91.53% <88.73%> (+7.56%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cofin
cofin merged commit aae6674 into main Aug 6, 2026
31 of 44 checks passed
@cofin
cofin deleted the fix/query-findings branch August 6, 2026 20:15
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.

to_schema: nested structs fail to decode when the outer struct's field names are unchanged by rename

2 participants