Skip to content

Serialize a dataclass schema to a field list - #315

Draft
farmio wants to merge 1 commit into
frenck:mainfrom
farmio:fix/serialize-nested-schema-nodes
Draft

Serialize a dataclass schema to a field list#315
farmio wants to merge 1 commit into
frenck:mainfrom
farmio:fix/serialize-nested-schema-nodes

Conversation

@farmio

@farmio farmio commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Breaking change

None. A dataclass schema raised before, so nothing that worked changes. Nested
mappings still raise.

Proposed change

to_field_list unwrapped a Schema to its node. For a dataclass schema that node
is the validate-then-construct pair, not the mapping, so it raised while the
equivalent TypedDictSchema serialized fine.

constructed_mapping() in dataclass_schema.py returns the mapping a
constructing schema validates, and to_field_list uses it before serializing.
Putting the check there keeps the shape of the pair private to the module that
builds it, rather than teaching the codec how a dataclass schema is assembled.

Nested mappings are left alone: voluptuous-serialize raises for those too, and a
test now pins both sides of that.

One open question for you. I added constructed_mapping as a module-level
function because create_dataclass_schema returns a plain Schema, so a method
or property on DataclassSchema would not cover the functional builder. If you
would rather not grow the module surface, the alternative is a shape check inside
the codec, which I liked less.

fixes #313

Type of change

  • Bugfix (non-breaking change that fixes an issue)

Additional information

Checklist

  • I fully understand the code in this pull request and can explain every line, including any AI-assisted changes.
  • The change is covered by tests, and uv run --no-sync just test passes locally.
  • uv run --no-sync just lint passes.
  • uv run --no-sync just typecheck passes.
  • No commented-out or dead code is left in the pull request.

to_field_list unwrapped a Schema to its node, which for a dataclass schema is
the validate-then-construct pair rather than the mapping, so it raised while
the equivalent TypedDict schema serialized fine. Unwrap to the mapping the
construction step consumes.

Nested mappings still raise, matching voluptuous-serialize, which has no
field-list shape for them either.
Copilot AI balanced review requested due to automatic review settings August 25, 2026 06:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codspeed-hq

codspeed-hq Bot commented Aug 25, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 23 untouched benchmarks


Comparing farmio:fix/serialize-nested-schema-nodes (756f732) with main (afa4b7a)

Open in CodSpeed

@farmio farmio added the bugfix Inconsistencies or issues which will cause a problem for users or implementers. label Aug 25, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (afa4b7a) to head (756f732).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #315   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           45        45           
  Lines         6590      6596    +6     
  Branches      1220      1221    +1     
=========================================
+ Hits          6590      6596    +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Inconsistencies or issues which will cause a problem for users or implementers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

to_field_list cannot serialize a dataclass schema

3 participants