Jump to solution
Verify

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%.

Jump to Verify Open PR/Commit
@@ -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
repro.py
class MyClass[T]: pass MyClassInt = MyClass[int] type(MyClassInt) # typing._GenericAlias isinstance(MyClass[int](), MyClass[int]) # TypeError
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
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.
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

  • Production symptom (often without a traceback): - For pydantic 2.10.6 the warning doesn't occur.

Proof / Evidence

Discussion

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

“> Regarding your first answer: I don't fully understand”
@Viicos · 2025-04-15 · confirmation · source
“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:”
@Viicos · 2025-04-14 · source
“Thank you, I adapted my code to your suggested approach in the second answer”
@stdkoehler · 2025-04-14 · source
“Bisected to https://github.com/pydantic/pydantic/pull/10704”
@Viicos · 2025-04-14 · source

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
signature.txt
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.txt
Error Message ------------- - For pydantic 2.10.6 the warning doesn't occur. raise ValueError(f"Unsupported type: {type(stage_data)}") from None

Minimal Reproduction

repro.py
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.

When NOT to use: This fix should not be applied if the caching behavior is required for specific use cases.

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

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

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix should not be applied if the caching behavior is required for specific use cases.

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.

Related Issues

No related fixes found.

Sources

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