Jump to solution
Verify

The Fix

pip install pydantic==1.10.1

Based on closed pydantic/pydantic issue #9243 · PR/commit linked

Jump to Verify Open PR/Commit
@@ -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
repro.py
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()
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.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

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?”
@sydney-runkle · 2024-04-16 · source
“I can reproduce on 2.5.3 (as an arbitrary version I checked against).”
@davidhewitt · 2024-04-16 · source

Failure Signature (Search String)

  • Memory leak when using Iterable
Copy-friendly signature
signature.txt
Failure Signature ----------------- Memory leak when using Iterable class Trace(BaseModel):

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Memory leak when using Iterable class Trace(BaseModel):

Minimal Reproduction

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

When NOT to use: Do not use if it changes public behavior or if the failure cannot be reproduced.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use if it changes public behavior or if the failure cannot be reproduced.

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

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