The Fix
pip install pydantic==1.10.18
Based on closed pydantic/pydantic issue #9947 · 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%.
@@ -488,10 +488,10 @@ def _from_dataclass_field(dc_field: DataclassField[Any]) -> FieldInfo:
default = dc_field.default
if default is dataclasses.MISSING:
- default = PydanticUndefined
+ default = _Unset
from typing import Annotated
from pydantic import Field
import pydantic.dataclasses
@pydantic.dataclasses.dataclass()
class ExampleReproducer:
val2: Annotated[int, Field(default_factory=lambda: 3)]
value = ExampleReproducer()
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==1.10.18\nWhen NOT to use: This fix is not applicable if using non-Annotated fields.\n\n
Why This Fix Works in Production
- Trigger: value = ExampleReproducer()
- Mechanism: Fixes the issue where the default_factory passed in Annotated was silently ignored in pydantic.dataclass.
- Why the fix works: Fixes the issue where the default_factory passed in Annotated was silently ignored in pydantic.dataclass. (first fixed release: 1.10.18).
- 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).
- Surfaces as: Traceback (most recent call last):
Proof / Evidence
- GitHub issue: #9947
- Fix PR: https://github.com/pydantic/pydantic/pull/9971
- First fixed release: 1.10.18
- 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.47
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Interesting, looks like this works for BaseModels but not dataclasses.”
“PRs welcome. I can try to address in v2.9 if this hasn't been picked up by then. I'm guessing a fix would be in make_pydantic_fields_compatible…”
“Hi @sydney-runkle, I'd be interested in investigating it further”
Failure Signature (Search String)
- value = ExampleReproducer()
Error Message
Stack trace
Error Message
-------------
Traceback (most recent call last):
File "test_pydantic.py", line 11, in <module>
value = ExampleReproducer()
^^^^^^^^^^^^^^^^^^^
File "/nix/store/fcjbczh74z9hx7ingvb5ydsa9fv5y81q-python3-3.12.4-env/lib/python3.12/site-packages/pydantic/_internal/_dataclasses.py", line 140, in __init__
s.__pydantic_validator__.validate_python(ArgsKwargs(args, kwargs), self_instance=s)
pydantic_core._pydantic_core.ValidationError: 1 validation error for ExampleReproducer
val2
Field required [type=missing, input_value=ArgsKwargs(()), input_type=ArgsKwargs]
For further information visit https://errors.pydantic.dev/2.7/v/missing
Minimal Reproduction
from typing import Annotated
from pydantic import Field
import pydantic.dataclasses
@pydantic.dataclasses.dataclass()
class ExampleReproducer:
val2: Annotated[int, Field(default_factory=lambda: 3)]
value = ExampleReproducer()
Environment
- Python: 3.12
What Broke
Instances of ExampleReproducer fail to initialize, raising a validation error for missing fields.
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==1.10.18
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/9971
First fixed release: 1.10.18
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is not applicable if using non-Annotated fields.
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 |
|---|---|
| 1.10.18 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.