Jump to solution
Verify

The Fix

pip install pydantic==2.11.0

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

Jump to Verify Open PR/Commit
@@ -1,19 +1,20 @@ from __future__ import annotations +import inspect import os -from collections import defaultdict
repro.py
# Setup: from typing import Union from pydantic import create_model simple_models = [ create_model( f"SimpleModel{i}", **{f"f{j}": (int, ...) for j in range(10)}, ) for i in range(20) ] UnionModels = Union[*simple_models] # Statement: Model = create_model( "Model", **{f"f{i}": (UnionModels, ...) for i in range(30)} )
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==2.11.0\nWhen NOT to use: Avoid this fix if the schema generation logic is expected to change frequently.\n\n

Why This Fix Works in Production

  • Trigger: Performance issues related to schema building
  • Mechanism: Performance issues arise from repeated schema building without caching mechanisms
  • Why the fix works: Refactor and optimize schema cleaning logic to improve performance during schema generation. (first fixed release: 2.11.0).

Why This Breaks in Prod

  • Performance issues arise from repeated schema building without caching mechanisms
  • Production symptom (often without a traceback): Performance issues related to schema building

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“This is a completely private API that is not intended to be used outside Pydantic. As I mentioned, we are in the process of designing…”
@Viicos · 2025-01-14 · source
“Also strongly related: https://github.com/pydantic/pydantic/issues/10036 and https://github.com/pydantic/pydantic/issues/10074 Given this, and my familiarity with the above code, I'd love to take a stab at a metadata refactor,…”
@sydney-runkle · 2024-09-04 · source
“Though the performance benefits might not be significant, I'd argue https://github.com/pydantic/pydantic/issues/10299 is related :). The less fluff we can have in that process, the better.”
@sydney-runkle · 2024-09-04 · source
“Would it be possible to pre-build everything, say as a JSON (with an option to compress), so users will deploy their app necessary artifacts for…”
@dmarxn · 2025-01-01 · source

Failure Signature (Search String)

  • Performance issues related to schema building
  • This issue gathers info about performance issues related to schema building. This strongly relates to https://github.com/pydantic/pydantic/discussions/6748. Only time performance
Copy-friendly signature
signature.txt
Failure Signature ----------------- Performance issues related to schema building This issue gathers info about performance issues related to schema building. This strongly relates to https://github.com/pydantic/pydantic/discussions/6748. Only time performance is in scope.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Performance issues related to schema building This issue gathers info about performance issues related to schema building. This strongly relates to https://github.com/pydantic/pydantic/discussions/6748. Only time performance is in scope.

Minimal Reproduction

repro.py
# Setup: from typing import Union from pydantic import create_model simple_models = [ create_model( f"SimpleModel{i}", **{f"f{j}": (int, ...) for j in range(10)}, ) for i in range(20) ] UnionModels = Union[*simple_models] # Statement: Model = create_model( "Model", **{f"f{i}": (UnionModels, ...) for i in range(30)} )

What Broke

Schema generation leads to significant delays, impacting application responsiveness.

Why It Broke

Performance issues arise from repeated schema building without caching mechanisms

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install pydantic==2.11.0

When NOT to use: Avoid this fix if the schema generation logic is expected to change frequently.

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/11244

First fixed release: 2.11.0

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

  • Avoid this fix if the schema generation logic is expected to change frequently.

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
2.11.0 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.