Jump to solution
Verify

The Fix

pip install pydantic==2.11.1

Based on closed pydantic/pydantic issue #11642 · PR/commit linked

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Jump to Verify Open PR/Commit
@@ -2813,7 +2813,7 @@ def _resolve_definition(self, ref: str, definitions: dict[str, CoreSchema]) -> C # a PEP 695 type alias (which is referenceable) that references another PEP 695 type alias): visited: set[str] = set() - while definition['type'] == 'definition-ref': + while definition['type'] == 'definition-ref' and _inlining_behavior(definition) == 'inline': schema_ref = definition['schema_ref']
repro.py
# /// script # requires-python = ">=3.12" # dependencies = [ # "pydantic==2.10.6", # ] # /// import pydantic from typing import Annotated class Foo(pydantic.BaseModel): spam: str = 'text' eggs: int = 123 type FooToJson = Annotated[ Foo, pydantic.PlainSerializer(lambda v: v.model_dump_json()), ] class Bar(pydantic.BaseModel): data: FooToJson = Foo() bar = Bar().model_dump() data_type = type(Bar().model_dump()['data']) print(bar) print(f'data type is {data_type}\n')
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install pydantic==2.11.1\nWhen NOT to use: Do not use this fix if you rely on the previous serialization behavior of returning a JSON string.\n\n

Why This Fix Works in Production

  • Trigger: PlainSerializer does not work correctly in 2.11
  • Mechanism: Fixes an issue where the PlainSerializer did not work correctly in Pydantic version 2.11, restoring the expected serialization behavior.
  • Why the fix works: Fixes an issue where the PlainSerializer did not work correctly in Pydantic version 2.11, restoring the expected serialization behavior. (first fixed release: 2.11.1).
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • Shows up under Python 3.12 in real deployments (not just unit tests).
  • Production symptom (often without a traceback): PlainSerializer does not work correctly in 2.11

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“Thanks for the report, this will be fixed in the next patch release.”
@Viicos · 2025-03-28 · confirmation · source

Failure Signature (Search String)

  • PlainSerializer does not work correctly in 2.11
  • In 2.10.6, the serializer worked correctly, but this changed after upgrading to version 2.11.
Copy-friendly signature
signature.txt
Failure Signature ----------------- PlainSerializer does not work correctly in 2.11 In 2.10.6, the serializer worked correctly, but this changed after upgrading to version 2.11.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- PlainSerializer does not work correctly in 2.11 In 2.10.6, the serializer worked correctly, but this changed after upgrading to version 2.11.

Minimal Reproduction

repro.py
# /// script # requires-python = ">=3.12" # dependencies = [ # "pydantic==2.10.6", # ] # /// import pydantic from typing import Annotated class Foo(pydantic.BaseModel): spam: str = 'text' eggs: int = 123 type FooToJson = Annotated[ Foo, pydantic.PlainSerializer(lambda v: v.model_dump_json()), ] class Bar(pydantic.BaseModel): data: FooToJson = Foo() bar = Bar().model_dump() data_type = type(Bar().model_dump()['data']) print(bar) print(f'data type is {data_type}\n')

Environment

  • Python: 3.12
  • Pydantic: 2

What Broke

Serialization output changed from JSON string to a dictionary, causing unexpected data types.

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install pydantic==2.11.1

When NOT to use: Do not use this fix if you rely on the previous serialization behavior of returning a JSON string.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/pydantic/pydantic/pull/11644

First fixed release: 2.11.1

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use this fix if you rely on the previous serialization behavior of returning a JSON string.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
  • Upgrade behind a canary and run integration tests against the canary before 100% rollout.

Version Compatibility Table

VersionStatus
2.11.1 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.