The Fix
pip install pydantic==2.6.2
Based on closed pydantic/pydantic issue #8730 · 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%.
@@ -8,7 +8,7 @@
import typing
import warnings
-from contextlib import contextmanager
+from contextlib import ExitStack, contextmanager
from copy import copy, deepcopy
### In a.py
from __future__ import annotations
import dataclasses
from typing import NewType
IntAlias = NewType("IntAlias", int)
@dataclasses.dataclass
class Base:
x: IntAlias
### In b.py
import dataclasses
import pydantic
import a
@dataclasses.dataclass
class Sub(a.Base): ...
if __name__ == "__main__":
print(pydantic.TypeAdapter(Sub).validate_python({"x": 1}))
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.6.2\nWhen NOT to use: Do not apply this fix if the dataclass does not use future annotations.\n\n
Why This Fix Works in Production
- Trigger: core_schema = _getattr_no_parents(type, '__pydantic_core_schema__')
- Mechanism: Pydantic does not consider base classes when building the type namespace for dataclasses
- Why the fix works: Fixes the resolution of forward references in dataclass base classes that are not present in the subclass module namespace, addressing issue #8730. (first fixed release: 2.6.2).
- 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
- Pydantic does not consider base classes when building the type namespace for dataclasses
- Surfaces as: Traceback (most recent call last):
Proof / Evidence
- GitHub issue: #8730
- Fix PR: https://github.com/pydantic/pydantic/pull/8751
- First fixed release: 2.6.2
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.35
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@alexmojaki, Could you please take a look at this issue when you have a chance? Thanks!”
“> The root cause is that when pydantic builds up the type namespace, it does not consider base classes (https://github.com/pydantic/pydantic/blob/main/pydantic/_internal/_generate_schema.py#L1474)”
Failure Signature (Search String)
- core_schema = _getattr_no_parents(type, '__pydantic_core_schema__')
Error Message
Stack trace
Error Message
-------------
Traceback (most recent call last):
File "C:\Users\matthew.joyce\Repos\lw8\venv\venv_develop\lib\site-packages\pydantic\type_adapter.py", line 207, in __init__
core_schema = _getattr_no_parents(type, '__pydantic_core_schema__')
File "C:\Users\matthew.joyce\Repos\lw8\venv\venv_develop\lib\site-packages\pydantic\type_adapter.py", line 98, in _getattr_no_parents
raise AttributeError(attribute)
AttributeError: __pydantic_core_schema__
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\matthew.joyce\Repos\lw8\venv\venv_develop\lib\site-packages\pydantic\_internal\_generate_schema.py", line 679, in _resolve_forward_ref
obj = _typing_extra.eval_type_backport(obj, globalns=self._types_namespace)
File "C:\Users\matthew.joyce\Repos\lw8\venv\venv_develop\lib\site-packages\pydantic\_internal\_typing_extra.py", line 240, in eval_type_backport
return typing._eval_type( # type: ignore
File "C:\Program Files\Python310\lib\typing.py", line 327, in _eval_type
return t._evaluate(globalns, localns, recursive_guard)
File "C:\Program Files\Python310\lib\typing.py", line 694, in _evaluate
eval(self.__forward_code__, globalns, localns),
File "<string>", line 1, in <module>
NameError: name 'IntAlias' is not defined
The above exception was the direct cause of the following exception:
Traceback (m
... (truncated) ...
Minimal Reproduction
### In a.py
from __future__ import annotations
import dataclasses
from typing import NewType
IntAlias = NewType("IntAlias", int)
@dataclasses.dataclass
class Base:
x: IntAlias
### In b.py
import dataclasses
import pydantic
import a
@dataclasses.dataclass
class Sub(a.Base): ...
if __name__ == "__main__":
print(pydantic.TypeAdapter(Sub).validate_python({"x": 1}))
Environment
- Pydantic: 2
What Broke
Errors occur when resolving type annotations in dataclass subclasses.
Why It Broke
Pydantic does not consider base classes when building the type namespace for dataclasses
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.6.2
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/8751
First fixed release: 2.6.2
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not apply this fix if the dataclass does not use future annotations.
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.6.2 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.