The Fix
pip install pydantic==2.11.0
Based on closed pydantic/pydantic issue #10695 · PR/commit linked
@@ -17,7 +17,7 @@
from pydantic.errors import PydanticUserError
-from . import _typing_extra
+from . import _generics, _typing_extra
from ._config import ConfigWrapper
from typing import TypeVar, Generic
from pydantic import BaseModel
T = TypeVar("T")
def test_ser():
class C(BaseModel):
pass
class X(BaseModel, Generic[T]):
y: "Y[T]"
class Y(BaseModel, Generic[T]):
obj: T
class PydanticModel(BaseModel): #<-- comment out this class and the test passes
x: "X[C]"
x = X[C](
y=Y[C](obj=C()),
)
assert isinstance(x, X)
assert isinstance(x.y, Y)
assert isinstance(x.y.obj, C)
j_c = x.model_dump_json()
deser_c = X[C].model_validate_json(j_c)
assert isinstance(deser_c, X)
assert isinstance(deser_c.y, Y)
assert isinstance(deser_c.y.obj, C) #<-- this line fails
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.0\nWhen NOT to use: This fix should not be applied if the model structure is fundamentally altered.\n\n
Why This Fix Works in Production
- Trigger: Declaring a generic attribute in a Pydantic model that itself has a generic attribute breaks deserialisation of the declared class
- Mechanism: The issue arises from incorrect handling of forward annotations during model field collection
- Why the fix works: Addresses issues with model field collection in Pydantic, particularly with forward annotations, ensuring accurate field definitions during model rebuilding. (first fixed release: 2.11.0).
- If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).
Why This Breaks in Prod
- Shows up under Python 3.12 in real deployments (not just unit tests).
- The issue arises from incorrect handling of forward annotations during model field collection
- Production symptom (often without a traceback): Declaring a generic attribute in a Pydantic model that itself has a generic attribute breaks deserialisation of the declared class
Proof / Evidence
- GitHub issue: #10695
- Fix PR: https://github.com/pydantic/pydantic/pull/11388
- First fixed release: 2.11.0
- 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.56
Verified Execution
We executed the runnable minimal repro in a temporary environment and captured exit codes + logs.
- Status: PASS
- Ran: 2026-02-11T16:52:29Z
- Package: pydantic
- Fixed: 2.11.0
- Mode: fixed_only
- Outcome: ok
Logs
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Internal details of the issue: 1”
Failure Signature (Search String)
- Declaring a generic attribute in a Pydantic model that itself has a generic attribute breaks deserialisation of the declared class
- assert isinstance(x, X)
Copy-friendly signature
Failure Signature
-----------------
Declaring a generic attribute in a Pydantic model that itself has a generic attribute breaks deserialisation of the declared class
assert isinstance(x, X)
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Declaring a generic attribute in a Pydantic model that itself has a generic attribute breaks deserialisation of the declared class
assert isinstance(x, X)
Minimal Reproduction
from typing import TypeVar, Generic
from pydantic import BaseModel
T = TypeVar("T")
def test_ser():
class C(BaseModel):
pass
class X(BaseModel, Generic[T]):
y: "Y[T]"
class Y(BaseModel, Generic[T]):
obj: T
class PydanticModel(BaseModel): #<-- comment out this class and the test passes
x: "X[C]"
x = X[C](
y=Y[C](obj=C()),
)
assert isinstance(x, X)
assert isinstance(x.y, Y)
assert isinstance(x.y.obj, C)
j_c = x.model_dump_json()
deser_c = X[C].model_validate_json(j_c)
assert isinstance(deser_c, X)
assert isinstance(deser_c.y, Y)
assert isinstance(deser_c.y.obj, C) #<-- this line fails
Environment
- Python: 3.12
- Pydantic: 2
What Broke
Deserialization of models results in incorrect types, leading to runtime errors.
Why It Broke
The issue arises from incorrect handling of forward annotations during model field collection
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.11.0
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/11388
First fixed release: 2.11.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if the model structure is fundamentally altered.
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.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.