Jump to solution
Verify

The Fix

pip install pydantic==1.10.1

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

Jump to Verify Open PR/Commit
@@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@ +Allow `Field` with a `default_factory` to be used as an argument to a function +decorated with `validate_arguments` \ No newline at end of file
repro.py
import datetime from typing import Annotated, Optional from pydantic import BaseModel, Field # Model Definition class Item(BaseModel): id: Annotated[int, Field(title="Item ID")] label: Annotated[str | None, Field(title="Item Label")] = None created_at: Annotated[datetime.datetime | None, Field(title="Item Created At", default_factory=datetime.datetime.now)] = None # Ok: Static Analysis Success. item = Item(id=1)
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.1\nWhen NOT to use: This fix should not be used if the existing behavior of Field is required.\n\nOption C — Workaround\nmight be to define a small helper function:\nWhen NOT to use: This fix should not be used if the existing behavior of Field is required.\n\n

Why This Fix Works in Production

  • Trigger: Annotated cannot be used, and Field must be assigned.
  • Mechanism: The current implementation does not allow using Field with default_factory in Annotated
  • Why the fix works: Adds preliminary support for Field to validate_arguments, allowing the use of default_factory in function arguments. (first fixed release: 1.10.1).

Why This Breaks in Prod

  • Shows up under Python 3.12 in real deployments (not just unit tests).
  • The current implementation does not allow using Field with default_factory in Annotated
  • Production symptom (often without a traceback): Annotated cannot be used, and Field must be assigned.

Proof / Evidence

Discussion

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

“@sydney-runkle Thanks for the response. Yes. I could not find an existing way to dictate **required** and **default**, and made a suggestion. If you have…”
@ya7010 · 2024-06-26 · source
“Just to clarify - when you specify the default_factory, it's inferred that the field is not required”
@sydney-runkle · 2024-06-26 · source
“Imo seems best for now to have it defined in user code, considering it is a two-line function, but I don't have strong opinions on…”
@Viicos · 2024-06-27 · source
“Hi @yassun7010, Perhaps I'm misunderstanding your question - why does the following not suit your needs?”
@sydney-runkle · 2024-06-26 · source

Failure Signature (Search String)

  • Annotated cannot be used, and Field must be assigned.
  • The reason why `Annotated` cannot be used when using `default_factory` is to avoid specifying a field with `default_factory` when initializing in the constructor.
Copy-friendly signature
signature.txt
Failure Signature ----------------- Annotated cannot be used, and Field must be assigned. The reason why `Annotated` cannot be used when using `default_factory` is to avoid specifying a field with `default_factory` when initializing in the constructor.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- Annotated cannot be used, and Field must be assigned. The reason why `Annotated` cannot be used when using `default_factory` is to avoid specifying a field with `default_factory` when initializing in the constructor.

Minimal Reproduction

repro.py
import datetime from typing import Annotated, Optional from pydantic import BaseModel, Field # Model Definition class Item(BaseModel): id: Annotated[int, Field(title="Item ID")] label: Annotated[str | None, Field(title="Item Label")] = None created_at: Annotated[datetime.datetime | None, Field(title="Item Created At", default_factory=datetime.datetime.now)] = None # Ok: Static Analysis Success. item = Item(id=1)

Environment

  • Python: 3.12

What Broke

Users cannot consistently declare fields with required and default values.

Why It Broke

The current implementation does not allow using Field with default_factory in Annotated

Fix Options (Details)

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

pip install pydantic==1.10.1

When NOT to use: This fix should not be used if the existing behavior of Field is required.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Option C — Workaround Temporary workaround

might be to define a small helper function:

When NOT to use: This fix should not be used if the existing behavior of Field is required.

Use only if you cannot change versions today. Treat this as a stopgap and remove once upgraded.

Fix reference: https://github.com/pydantic/pydantic/pull/2176

First fixed release: 1.10.1

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 used if the existing behavior of Field is required.

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

Related Issues

No related fixes found.

Sources

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