Jump to solution
Verify

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%.

Jump to Verify Open PR/Commit
@@ -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
repro.py
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()
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==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).
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).
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

Discussion

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

“Interesting, looks like this works for BaseModels but not dataclasses.”
@sydney-runkle · 2024-07-24 · source
“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…”
@sydney-runkle · 2024-07-24 · source
“Hi @sydney-runkle, I'd be interested in investigating it further”
@AlessandroMiola · 2024-07-24 · source

Failure Signature (Search String)

  • value = ExampleReproducer()

Error Message

Stack trace
error.txt
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

repro.py
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

When NOT to use: This fix is not applicable if using non-Annotated fields.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix is not applicable if using non-Annotated fields.

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
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.