The Fix
pip install pydantic==2.11.0
Based on closed pydantic/pydantic issue #10297 · PR/commit linked
@@ -1,19 +1,20 @@
from __future__ import annotations
+import inspect
import os
-from collections import defaultdict
# Setup:
from typing import Union
from pydantic import create_model
simple_models = [
create_model(
f"SimpleModel{i}",
**{f"f{j}": (int, ...) for j in range(10)},
)
for i in range(20)
]
UnionModels = Union[*simple_models]
# Statement:
Model = create_model(
"Model",
**{f"f{i}": (UnionModels, ...) for i in range(30)}
)
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: Avoid this fix if the schema generation logic is expected to change frequently.\n\n
Why This Fix Works in Production
- Trigger: Performance issues related to schema building
- Mechanism: Performance issues arise from repeated schema building without caching mechanisms
- Why the fix works: Refactor and optimize schema cleaning logic to improve performance during schema generation. (first fixed release: 2.11.0).
Why This Breaks in Prod
- Performance issues arise from repeated schema building without caching mechanisms
- Production symptom (often without a traceback): Performance issues related to schema building
Proof / Evidence
- GitHub issue: #10297
- Fix PR: https://github.com/pydantic/pydantic/pull/11244
- First fixed release: 2.11.0
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.62
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“This is a completely private API that is not intended to be used outside Pydantic. As I mentioned, we are in the process of designing…”
“Also strongly related: https://github.com/pydantic/pydantic/issues/10036 and https://github.com/pydantic/pydantic/issues/10074 Given this, and my familiarity with the above code, I'd love to take a stab at a metadata refactor,…”
“Though the performance benefits might not be significant, I'd argue https://github.com/pydantic/pydantic/issues/10299 is related :). The less fluff we can have in that process, the better.”
“Would it be possible to pre-build everything, say as a JSON (with an option to compress), so users will deploy their app necessary artifacts for…”
Failure Signature (Search String)
- Performance issues related to schema building
- This issue gathers info about performance issues related to schema building. This strongly relates to https://github.com/pydantic/pydantic/discussions/6748. Only time performance
Copy-friendly signature
Failure Signature
-----------------
Performance issues related to schema building
This issue gathers info about performance issues related to schema building. This strongly relates to https://github.com/pydantic/pydantic/discussions/6748. Only time performance is in scope.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Performance issues related to schema building
This issue gathers info about performance issues related to schema building. This strongly relates to https://github.com/pydantic/pydantic/discussions/6748. Only time performance is in scope.
Minimal Reproduction
# Setup:
from typing import Union
from pydantic import create_model
simple_models = [
create_model(
f"SimpleModel{i}",
**{f"f{j}": (int, ...) for j in range(10)},
)
for i in range(20)
]
UnionModels = Union[*simple_models]
# Statement:
Model = create_model(
"Model",
**{f"f{i}": (UnionModels, ...) for i in range(30)}
)
What Broke
Schema generation leads to significant delays, impacting application responsiveness.
Why It Broke
Performance issues arise from repeated schema building without caching mechanisms
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/11244
First fixed release: 2.11.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Avoid this fix if the schema generation logic is expected to change frequently.
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.
- Track RSS + object counts after deployments; alert on monotonic growth and GC pressure.
- Add a long-running test that repeats the failing call path and asserts stable memory.
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.