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%.
@@ -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.
from pydantic import BaseModel
from typing import Sequence
type MySeq[T] = Sequence[T]
type MyIntSeq = MySeq[int]
class MyModel(BaseModel):
my_int_seq: MyIntSeq
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==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).
- 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
- GitHub issue: #8984
- Fix PR: https://github.com/pydantic/pydantic/pull/10809
- First fixed release: 2.10.0
- 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.27
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..”
“Maybe I'm being dumb, but I don't think your code is valid python.”
“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…”
“https://docs.python.org/3/library/typing.html#type-aliases - type statement new in 3.12”
Failure Signature (Search String)
- class MyModel(BaseModel):
Error Message
Stack trace
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 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
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
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.
When NOT to Use This Fix
- This fix should not be applied if the type aliases do not reference each other.
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.
Version Compatibility Table
| Version | Status |
|---|---|
| 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.