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%.
@@ -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']
# /// 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')
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
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).
- 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
- GitHub issue: #11642
- Fix PR: https://github.com/pydantic/pydantic/pull/11644
- First fixed release: 2.11.1
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.95
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.49
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.”
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
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 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
# /// 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
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.
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
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
| Version | Status |
|---|---|
| 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.