Jump to solution
Verify

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.

Jump to Verify Open PR/Commit
@@ -385,6 +385,7 @@ 'FieldValidationInfo': ('pydantic_core', '.core_schema'), } +_deprecated_dynamic_imports = {'FieldValidationInfo'} _getattr_migration = getattr_migration(__name__)
repro.py
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()
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
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).
Production impact:
  • 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

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”
@sydney-runkle · 2024-08-01 · confirmation · source
“@PoncinMatthieu, Thanks for reporting this. I'll tag this with a performance tag and we'll dig in!”
@sydney-runkle · 2024-05-21 · source
“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…”
@algoqt · 2024-06-04 · source
“@sydney-runkle Is there an expected timeline for this performance issue to be addressed ? We are also facing performance bottlenecks due to isinstance checks.”
@rasswanth-s · 2024-07-24 · source

Failure Signature (Search String)

  • 500004 function calls in 0.054 seconds
  • exchange :str = ''
Copy-friendly signature
signature.txt
Failure Signature ----------------- 500004 function calls in 0.054 seconds exchange :str = ''

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- 500004 function calls in 0.054 seconds exchange :str = ''

Minimal Reproduction

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

When NOT to use: Do not apply this fix if using Pydantic V1 or if performance is not an issue.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not apply this fix if using Pydantic V1 or if performance is not an issue.

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.

Version Compatibility Table

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