The Fix
pip install pydantic==1.10.1
Based on closed pydantic/pydantic issue #9243 · PR/commit linked
@@ -10,7 +10,7 @@
import traceback
from pathlib import Path
-from typing import Any, List
+from typing import Any, List, Tuple
from unittest.mock import patch
from collections.abc import Iterable
from pydantic import BaseModel
class Trace(BaseModel):
elements: Iterable[int]
for _ in range(1000000):
Trace(elements=[1, 2, 3])
import objgraph
objgraph.show_most_common_types()
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.1\nWhen NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.\n\n
Why This Fix Works in Production
- Trigger: Memory leak when using Iterable
- Mechanism: Memory usage grows due to improper handling of Iterable in Pydantic models
- Why the fix works: Fixes a memory leak issue when using Iterable in Pydantic models by updating package dependencies. (first fixed release: 1.10.1).
Why This Breaks in Prod
- Shows up under Python 3.12 in real deployments (not just unit tests).
- Memory usage grows due to improper handling of Iterable in Pydantic models
- Production symptom (often without a traceback): Memory leak when using Iterable
Proof / Evidence
- GitHub issue: #9243
- Fix PR: https://github.com/pydantic/pydantic-core/pull/1271
- First fixed release: 1.10.1
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.95
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.74
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@afdw, Hmm, this doesn't look great. It also doesn't look like it was introduced in v2.7.0. Could you please confirm?”
“I can reproduce on 2.5.3 (as an arbitrary version I checked against).”
Failure Signature (Search String)
- Memory leak when using Iterable
Copy-friendly signature
Failure Signature
-----------------
Memory leak when using Iterable
class Trace(BaseModel):
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Memory leak when using Iterable
class Trace(BaseModel):
Minimal Reproduction
from collections.abc import Iterable
from pydantic import BaseModel
class Trace(BaseModel):
elements: Iterable[int]
for _ in range(1000000):
Trace(elements=[1, 2, 3])
import objgraph
objgraph.show_most_common_types()
Environment
- Python: 3.12
- Pydantic: 2
What Broke
Repeated validation of Iterable causes significant memory leaks in production.
Why It Broke
Memory usage grows due to improper handling of Iterable in Pydantic models
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==1.10.1
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/pydantic/pydantic-core/pull/1271
First fixed release: 1.10.1
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use if it changes public behavior or if the failure cannot be reproduced.
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 |
|---|---|
| 1.10.1 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.