The Fix
pip install pydantic==1.10.18
Based on closed pydantic/pydantic issue #9458 · PR/commit linked
Production note: Watch p95/p99 latency and retry volume; timeouts can turn into retry storms and duplicate side-effects.
@@ -385,6 +385,7 @@
'FieldValidationInfo': ('pydantic_core', '.core_schema'),
}
+_deprecated_dynamic_imports = {'FieldValidationInfo'}
_getattr_migration = getattr_migration(__name__)
import cProfile
import pydantic
from pydantic import v1 as pydantic_v1
class BasicModelV1(pydantic_v1.BaseModel):
my_str: str
class BasicModelV2(pydantic.BaseModel):
my_str: str
doc_v1 = BasicModelV1(my_str="hello")
doc_v2 = BasicModelV2(my_str="hello")
print("cProfile pydantic.v1.BaseModel with doc_v1:")
with cProfile.Profile() as pr:
for i in range(0, 100000):
isinstance(doc_v1, pydantic_v1.BaseModel)
pr.print_stats()
print("cProfile pydantic.v1.BaseModel with doc_v2:")
with cProfile.Profile() as pr:
for i in range(0, 100000):
isinstance(doc_v2, pydantic_v1.BaseModel)
pr.print_stats()
print("cProfile pydantic.BaseModel with doc_v1:")
with cProfile.Profile() as pr:
for i in range(0, 100000):
isinstance(doc_v1, pydantic.BaseModel)
pr.print_stats()
print("cProfile pydantic.BaseModel with doc_v2:")
with cProfile.Profile() as pr:
for i in range(0, 100000):
isinstance(doc_v2, pydantic.BaseModel)
pr.print_stats()
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: Do not apply this fix if using Pydantic V1 or if performance is not an issue.\n\n
Why This Fix Works in Production
- Trigger: 500004 function calls in 0.054 seconds
- Mechanism: Performance issues in Pydantic V2 due to slow isinstance checks
- Why the fix works: Improved import times for modules using caching, addressing performance issues related to isinstance checks in Pydantic V2. (first fixed release: 1.10.18).
- If left unfixed, tail latency can spike under load and surface as timeouts/retries (amplifying incident impact).
Why This Breaks in Prod
- Shows up under Python 3.10.9 in real deployments (not just unit tests).
- Performance issues in Pydantic V2 due to slow isinstance checks
- Production symptom (often without a traceback): 500004 function calls in 0.054 seconds
Proof / Evidence
- GitHub issue: #9458
- Fix PR: https://github.com/pydantic/pydantic/pull/10009
- First fixed release: 1.10.18
- 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.47
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Good news! We've got a big speedup now. These are the results on main: Marking this as resolved by https://github.com/pydantic/pydantic/pull/10009”
“@PoncinMatthieu, Thanks for reporting this. I'll tag this with a performance tag and we'll dig in!”
“mds = [convert_to_md(item) for item in items] convert_to_md is a function convert item to class MarketDepth ,which with BaseModel is 10~20 times slower than without…”
“@sydney-runkle Is there an expected timeline for this performance issue to be addressed ? We are also facing performance bottlenecks due to isinstance checks.”
Failure Signature (Search String)
- 500004 function calls in 0.054 seconds
- exchange :str = ''
Copy-friendly signature
Failure Signature
-----------------
500004 function calls in 0.054 seconds
exchange :str = ''
Error Message
Signature-only (no traceback captured)
Error Message
-------------
500004 function calls in 0.054 seconds
exchange :str = ''
Minimal Reproduction
import cProfile
import pydantic
from pydantic import v1 as pydantic_v1
class BasicModelV1(pydantic_v1.BaseModel):
my_str: str
class BasicModelV2(pydantic.BaseModel):
my_str: str
doc_v1 = BasicModelV1(my_str="hello")
doc_v2 = BasicModelV2(my_str="hello")
print("cProfile pydantic.v1.BaseModel with doc_v1:")
with cProfile.Profile() as pr:
for i in range(0, 100000):
isinstance(doc_v1, pydantic_v1.BaseModel)
pr.print_stats()
print("cProfile pydantic.v1.BaseModel with doc_v2:")
with cProfile.Profile() as pr:
for i in range(0, 100000):
isinstance(doc_v2, pydantic_v1.BaseModel)
pr.print_stats()
print("cProfile pydantic.BaseModel with doc_v1:")
with cProfile.Profile() as pr:
for i in range(0, 100000):
isinstance(doc_v1, pydantic.BaseModel)
pr.print_stats()
print("cProfile pydantic.BaseModel with doc_v2:")
with cProfile.Profile() as pr:
for i in range(0, 100000):
isinstance(doc_v2, pydantic.BaseModel)
pr.print_stats()
Environment
- Python: 3.10.9
- Pydantic: 2
What Broke
Significant slowdowns in application startup and test suite execution.
Why It Broke
Performance issues in Pydantic V2 due to slow isinstance checks
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/10009
First fixed release: 1.10.18
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not apply this fix if using Pydantic V1 or if performance is not an issue.
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.