Skip to content

Restore pickling of Pydantic data converters - #1877

Merged
tconley1428 merged 3 commits into
mainfrom
fix/pydantic-converter-pickling
Sep 17, 2026
Merged

tconley1428 merged 3 commits into
mainfrom
fix/pydantic-converter-pickling

Conversation

@tconley1428

Copy link
Copy Markdown
Contributor

Fixes #1871.

Pydantic data converters fail to pickle because their type adapter cache wraps TypeAdapter in an instance-local lru_cache. Exclude that wrapper and its contents from pickled state, then recreate an empty cache with the same size limit when unpickling. Other converter state, including JSON options, is preserved.

Adds three regression cases covering the shipped data converter and empty/populated caches, verifying that a nondefault cache limit and JSON options survive unpickling. Includes a docstring note and changelog entry.

Validation:

  • Three pickle regression cases pass.
  • All 12 existing type adapter cache tests pass.
  • poe format and poe lint pass.
  • Tests ran with poe test -s -n 0 -p no:rerunfailures tests/contrib/pydantic/test_pydantic.py -k pickle (the rerun plugin requires a local socket unavailable in the sandbox).

@tconley1428
tconley1428 marked this pull request as ready for review September 16, 2026 18:43
@tconley1428
tconley1428 requested a review from a team as a code owner September 16, 2026 18:43
@tconley1428
tconley1428 merged commit 9664700 into main Sep 17, 2026
32 of 34 checks passed
@tconley1428
tconley1428 deleted the fix/pydantic-converter-pickling branch September 17, 2026 17:56
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.

[Bug] Pydantic DataConverter is no longer picklable in 1.32.0, breaking multiprocessing startup

2 participants