Jump to solution
Verify

The Fix

pip install pydantic==2.10.0

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

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Jump to Verify Open PR/Commit
@@ -522,6 +522,25 @@ except PydanticUserError as exc_info: ``` +## Circular reference schema {#circular-reference-schema} + +This error is raised when a circular reference is found that would otherwise result in an infinite recursion.
repro.py
from pydantic import BaseModel from typing import Sequence type MySeq[T] = Sequence[T] type MyIntSeq = MySeq[int] class MyModel(BaseModel): my_int_seq: MyIntSeq
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.10.0\nWhen NOT to use: This fix should not be applied if the type aliases do not reference each other.\n\n

Why This Fix Works in Production

  • Trigger: class MyModel(BaseModel):
  • Mechanism: A circular reference in type aliases causes Pydantic to fail during schema validation
  • Why the fix works: Fixes an error when using type aliases referencing other type aliases in Pydantic. (first fixed release: 2.10.0).
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • Shows up under Python 3.12 in real deployments (not just unit tests).
  • A circular reference in type aliases causes Pydantic to fail during schema validation
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

Discussion

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

“I believe this is a bug in our handling of nested type aliases. Definitely intend to fix it, not sure how complicated it will be..”
@dmontagu · 2024-03-12 · source
“Maybe I'm being dumb, but I don't think your code is valid python.”
@samuelcolvin · 2024-03-11 · source
“Why do you think that? Python 3.12 will execute the code if I use a dataclass instead of BaseModel, and pyright finds no issue with…”
@multimeric · 2024-03-11 · source
“https://docs.python.org/3/library/typing.html#type-aliases - type statement new in 3.12”
@davidhewitt · 2024-03-12 · source

Failure Signature (Search String)

  • class MyModel(BaseModel):

Error Message

Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File "/Users/milton.m/Programming/cyton-solver/backend/test_model.py", line 7, in <module> class MyModel(BaseModel): File "/Users/milton.m/Programming/cyton-solver/venv/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 183, in __new__ complete_model_class( File "/Users/milton.m/Programming/cyton-solver/venv/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 535, in complete_model_class cls.__pydantic_validator__ = create_schema_validator( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/milton.m/Programming/cyton-solver/venv/lib/python3.12/site-packages/pydantic/plugin/_schema_validator.py", line 49, in create_schema_validator return SchemaValidator(schema, config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pydantic_core._pydantic_core.SchemaError: Definitions error: definition `__main__.MySeq:4304815984[int:4316993544]` was never filled
Stack trace
error.txt
Error Message ------------- causes Traceback (most recent call last): File "/path/to/proj/.venv/lib64/python3.12/site-packages/pydantic/type_adapter.py", line 217, in __init__ validator = _getattr_no_parents(type, '__pydantic_validator__') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/proj/.venv/lib64/python3.12/site-packages/pydantic/type_adapter.py", line 98, in _getattr_no_parents raise AttributeError(attribute) AttributeError: __pydantic_validator__ During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/path/to/proj/main.py", line 14, in <module> adapter = TypeAdapter(JSONs) ^^^^^^^^^^^^^^^^^^ File "/path/to/proj/.venv/lib64/python3.12/site-packages/pydantic/type_adapter.py", line 222, in __init__ validator = create_schema_validator( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/proj/.venv/lib64/python3.12/site-packages/pydantic/plugin/_schema_validator.py", line 49, in create_schema_validator return SchemaValidator(schema, config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pydantic_core._pydantic_core.SchemaError: Definitions error: definition `__main__.JSON:1234` was never filled If I replace `type MyJSONAlias = JSON` by `MyJSONAlias = JSON`, then everything works. So I guess this is related to Python 3.12 `type` aliases and their lazy evaluation? He ... (truncated) ...

Minimal Reproduction

repro.py
from pydantic import BaseModel from typing import Sequence type MySeq[T] = Sequence[T] type MyIntSeq = MySeq[int] class MyModel(BaseModel): my_int_seq: MyIntSeq

Environment

  • Python: 3.12
  • Pydantic: 2

What Broke

Users encounter SchemaError when using nested type aliases in Pydantic models.

Why It Broke

A circular reference in type aliases causes Pydantic to fail during schema validation

Fix Options (Details)

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

pip install pydantic==2.10.0

When NOT to use: This fix should not be applied if the type aliases do not reference each other.

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

First fixed release: 2.10.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

  • This fix should not be applied if the type aliases do not reference each other.

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

Related Issues

No related fixes found.

Sources

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