The Fix
pip install pydantic==1.10.18
Based on closed pydantic/pydantic issue #9905 · PR/commit linked
@@ -5,7 +5,7 @@
strategy = []
lock_version = "4.5.0"
-content_hash = "sha256:fed880fb16df36669085143f0cdd13d107aec46ffa217055b64d8d687f6ca9e2"
+content_hash = "sha256:e0aaf99826f0ab2aa870c1dafa4d9939c7a60160cb870f681769806ec45c4f5d"
**pydantic_v1.py** (version 1.10.17)
import k8s_v1
**pydantic_v2.py** (version 2.8.2)
import k8s_v2
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==1.10.18\nWhen NOT to use: This fix should not be used if the application relies on the parent namespace caching for model definitions.\n\n
Why This Fix Works in Production
- Trigger: For example, generating a single python file that contains all Pydantic models from the Swagger API schemas below demonstrates this issue clearly.
- Mechanism: The import performance degradation in Pydantic v2 is due to heavy parent namespace preparation logic
- Why the fix works: Introduces an experimental feature to opt-in for faster model building by skipping heavy parent namespace preparation logic, addressing performance issues related to model imports. (first fixed release: 1.10.18).
Why This Breaks in Prod
- Shows up under Python 3.9 in real deployments (not just unit tests).
- The import performance degradation in Pydantic v2 is due to heavy parent namespace preparation logic
- Production symptom (often without a traceback): For example, generating a single python file that contains all Pydantic models from the Swagger API schemas below demonstrates this issue clearly.
Proof / Evidence
- GitHub issue: #9905
- Fix PR: https://github.com/pydantic/pydantic/pull/10113
- First fixed release: 1.10.18
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.75
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.71
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“2.11 (final released planned by the end of March) brings significant performance improvements related to constructing models, in particular core schema building [^1]”
“Pydantic v2 significantly slower than v1 It have been acknowledged and I think put in the v2.9.0 roadmap already.”
“Indeed, we're working on improvements now. @nix010, thanks for linking those! I'll tag this with performance so that we can track this example as we…”
“I'm currently working on this issue and plan to hopefully push a fix for v2.9!”
Failure Signature (Search String)
- For example, generating a single python file that contains all Pydantic models from the Swagger API schemas below demonstrates this issue clearly.
- datamodel-codegen --url https://github.com/kubernetes/kubernetes/raw/master/api/openapi-spec/swagger.json > k8s_v1.py
Copy-friendly signature
Failure Signature
-----------------
For example, generating a single python file that contains all Pydantic models from the Swagger API schemas below demonstrates this issue clearly.
datamodel-codegen --url https://github.com/kubernetes/kubernetes/raw/master/api/openapi-spec/swagger.json > k8s_v1.py
Error Message
Signature-only (no traceback captured)
Error Message
-------------
For example, generating a single python file that contains all Pydantic models from the Swagger API schemas below demonstrates this issue clearly.
datamodel-codegen --url https://github.com/kubernetes/kubernetes/raw/master/api/openapi-spec/swagger.json > k8s_v1.py
Minimal Reproduction
**pydantic_v1.py** (version 1.10.17)
import k8s_v1
**pydantic_v2.py** (version 2.8.2)
import k8s_v2
Environment
- Python: 3.9
- Pydantic: 2
What Broke
Importing models in Pydantic v2 takes significantly longer, leading to increased application startup times.
Why It Broke
The import performance degradation in Pydantic v2 is due to heavy parent namespace preparation logic
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==1.10.18
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/10113
First fixed release: 1.10.18
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if the application relies on the parent namespace caching for model definitions.
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 |
|---|---|
| 1.10.18 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.