Jump to solution
Verify

The Fix

pip install pydantic==1.10.19

Based on closed pydantic/pydantic issue #11235 · 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
@@ -300,6 +300,8 @@ jobs: - name: run typechecking integration tests (Mypy) + # Flaky: + if: false run: make test-typechecking-mypy
repro.py
def get_default() -> int: ... class MyModel(BaseModel): # get_default returns an int, but a bool is expected xyz: bool = Field(default_factory=get_default)
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.19\nWhen NOT to use: This fix should not be applied if the default factory's return type is intentionally different from the field type.\n\n

Why This Fix Works in Production

  • Trigger: When the return type of a default factory does not match the field type, the static type checker does not detect this mis-match.
  • Mechanism: The return type of the default factory does not match the field type, causing type checking issues
  • Why the fix works: Implements type checking for the `default` and `default_factory` arguments in Pydantic models, ensuring that the return type of a default factory matches the field type. (first fixed release: 1.10.19).
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.9 in real deployments (not just unit tests).
  • The return type of the default factory does not match the field type, causing type checking issues
  • Production symptom (often without a traceback): When the return type of a default factory does not match the field type, the static type checker does not detect this mis-match.

Proof / Evidence

Discussion

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

“Please upgrade to 2.10. This was implemented in https://github.com/pydantic/pydantic/pull/10651.”
@Viicos · 2025-01-08 · source

Failure Signature (Search String)

  • When the return type of a default factory does not match the field type, the static type checker does not detect this mis-match.
  • In the example code, the field `xyz` is a `bool` and the `get_default` function assigned to the `default_factory` returns an `int`. I would expect a static type checker to
Copy-friendly signature
signature.txt
Failure Signature ----------------- When the return type of a default factory does not match the field type, the static type checker does not detect this mis-match. In the example code, the field `xyz` is a `bool` and the `get_default` function assigned to the `default_factory` returns an `int`. I would expect a static type checker to detected that `get_default` does not return an `int`.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- When the return type of a default factory does not match the field type, the static type checker does not detect this mis-match. In the example code, the field `xyz` is a `bool` and the `get_default` function assigned to the `default_factory` returns an `int`. I would expect a static type checker to detected that `get_default` does not return an `int`.

Minimal Reproduction

repro.py
def get_default() -> int: ... class MyModel(BaseModel): # get_default returns an int, but a bool is expected xyz: bool = Field(default_factory=get_default)

Environment

  • Python: 3.9
  • Pydantic: 2

What Broke

Static type checker fails to detect mismatched types in Pydantic models, leading to potential runtime errors.

Why It Broke

The return type of the default factory does not match the field type, causing type checking issues

Fix Options (Details)

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

pip install pydantic==1.10.19

When NOT to use: This fix should not be applied if the default factory's return type is intentionally different from the field type.

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/10651

First fixed release: 1.10.19

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 applied if the default factory's return type is intentionally different from the field type.

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

Related Issues

No related fixes found.

Sources

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