Skip to content
This repository was archived by the owner on Apr 11, 2026. It is now read-only.

fix issue with field_serializers on nested typed dicts - #1879

Merged
davidhewitt merged 3 commits into
mainfrom
dh/state-model
Nov 3, 2025
Merged

fix issue with field_serializers on nested typed dicts#1879
davidhewitt merged 3 commits into
mainfrom
dh/state-model

Conversation

@davidhewitt

Copy link
Copy Markdown
Collaborator

Change Summary

This cleans up a bunch of FIXME comments I left regarding state.model handling in #1860.

It turns out for the most part that a lot of the stuff going on in fields.rs was redundant because model and dataclass serializers were already setting state.model. However for TypedDict, the code in fields.rs was supposed to be setting the model... but it was doing so extremely inconsistenty, and with problems for nested typed dicts.

The added test fails on main, passes the wrong typed dict to the nested field serializer.

I simplified the control flow by just adding a thin TypedDictSerializer wrapper which sets the state up in the same way as is done for models and dataclasses.

Related issue number

N/A

Checklist

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with this pydantic-core (except for expected changes)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@davidhewitt
davidhewitt requested a review from Viicos November 1, 2025 18:42
@codspeed-hq

codspeed-hq Bot commented Nov 1, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #1879 will not alter performance

Comparing dh/state-model (d165e68) with main (20d576b)

Summary

✅ 163 untouched

Comment thread tests/serializers/test_typed_dict.py Outdated
@davidhewitt
davidhewitt merged commit bed9c14 into main Nov 3, 2025
32 checks passed
@davidhewitt
davidhewitt deleted the dh/state-model branch November 3, 2025 12:24
davidhewitt added a commit to pydantic/pydantic that referenced this pull request Nov 5, 2025
…ntic-core#1879)

Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>

Original-commit-link: pydantic/pydantic-core@bed9c14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants