The Fix
Removes the generics cache workaround that caused warnings in Pydantic versions >= 2.11.0.
Based on closed pydantic/pydantic issue #11747 · 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%.
@@ -908,12 +908,7 @@ def __class_getitem__(
submodel = _generics.create_generic_submodel(model_name, origin, args, params)
- # Cache the generated model *only* if not in the process of parametrizing
- # another model. In some valid scenarios, we miss the opportunity to cache
- # it but in some cases this results in `PydanticRecursiveRef` instances left
class MyClass[T]: pass
MyClassInt = MyClass[int]
type(MyClassInt) # typing._GenericAlias
isinstance(MyClass[int](), MyClass[int]) # TypeError
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Apply the official fix\nRemoves the generics cache workaround that caused warnings in Pydantic versions >= 2.11.0.\nWhen NOT to use: This fix should not be applied if the caching behavior is required for specific use cases.\n\n
Why This Fix Works in Production
- Trigger: - For pydantic 2.10.6 the warning doesn't occur.
- Mechanism: Removes the generics cache workaround that caused warnings in Pydantic versions >= 2.11.0.
- 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
- Production symptom (often without a traceback): - For pydantic 2.10.6 the warning doesn't occur.
Proof / Evidence
- GitHub issue: #11747
- Fix PR: https://github.com/pydantic/pydantic/pull/11755
- Reproduced locally: No (not executed)
- Last verified: 2026-02-11
- Confidence: 0.70
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.57
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“> Regarding your first answer: I don't fully understand”
“Note that if you want to avoid relying on the isinstance() checks in get_stage() (which we recommend not doing), you can use the following implementation:”
“Thank you, I adapted my code to your suggested approach in the second answer”
“Bisected to https://github.com/pydantic/pydantic/pull/10704”
Failure Signature (Search String)
- - For pydantic 2.10.6 the warning doesn't occur.
- raise ValueError(f"Unsupported type: {type(stage_data)}") from None
Copy-friendly signature
Failure Signature
-----------------
- For pydantic 2.10.6 the warning doesn't occur.
raise ValueError(f"Unsupported type: {type(stage_data)}") from None
Error Message
Signature-only (no traceback captured)
Error Message
-------------
- For pydantic 2.10.6 the warning doesn't occur.
raise ValueError(f"Unsupported type: {type(stage_data)}") from None
Minimal Reproduction
class MyClass[T]: pass
MyClassInt = MyClass[int]
type(MyClassInt) # typing._GenericAlias
isinstance(MyClass[int](), MyClass[int]) # TypeError
Environment
- Pydantic: 2
What Broke
Users receive confusing warnings during serialization in production environments.
Fix Options (Details)
Option A — Apply the official fix
Removes the generics cache workaround that caused warnings in Pydantic versions >= 2.11.0.
Fix reference: https://github.com/pydantic/pydantic/pull/11755
Last verified: 2026-02-11. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if the caching behavior is required for specific use cases.
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.
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.