Jump to solution
Verify

The Fix

pip install pydantic==1.10.14

Based on closed pydantic/pydantic issue #9093 · 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
@@ -1018,5 +1018,32 @@ except PydanticUserError as exc_info: ``` +## Cannot evaluate type annotation {#unevaluable-type-annotation} + +Because type annotations are evaluated *after* assignments, you might get unexpected results when using a type annotation name
repro.py
from __future__ import annotations from pydantic import BaseModel, Field class Aaa(BaseModel): b: str = None class X(BaseModel): Aaa: Aaa = Field(None) # This crashes # Aaa: "Aaa" = Field(None) # Likewise # Aaa: Aaa = None # This is fine
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.14\nWhen NOT to use: This fix is not applicable when field names do not clash with type annotations.\n\n

Why This Fix Works in Production

  • Trigger: class X(BaseModel):
  • Mechanism: Using a default Field crashes when the type annotation references a class of the same name as the field
  • Why the fix works: Explicitly raises an error if field names clash with types, addressing a specific bug where using a default Field crashes when the type annotation references a class of the same name as the field. (first fixed release: 1.10.14).
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.10 in real deployments (not just unit tests).
  • Using a default Field crashes when the type annotation references a class of the same name as the field
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

Discussion

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

“I'd say we should close it given we can't really do much here as said in the previous comments”
@Viicos · 2024-10-04 · source
“@lmmx, Thanks for the detailed bug report. I know that @Viicos worked on a PR recently to disallow / warn for cases similar to yours…”
@sydney-runkle · 2024-03-25 · source
“> I use flake8 all the time (even though my pre-commit is in ruff now so cool to see the plans for that!) My plan…”
@Viicos · 2024-03-25 · source
“@Viicos, do you think this still fits within the scope of v2.10?”
@sydney-runkle · 2024-10-04 · source

Failure Signature (Search String)

  • class X(BaseModel):

Error Message

Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File "/home/louis/lab/tubeulator/pascalify/Journey.py", line 10, in <module> class X(BaseModel): File "/home/louis/miniconda3/envs/tubeulator/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 178, in __new__ set_model_fields(cls, bases, config_wrapper, types_namespace) File "/home/louis/miniconda3/envs/tubeulator/lib/python3.10/site-packages/pydantic/_internal/_model_construction.py", line 452, in set_model_fields fields, class_vars = collect_model_fields(cls, bases, config_wrapper, types_namespace, typevars_map=typevars_map) File "/home/louis/miniconda3/envs/tubeulator/lib/python3.10/site-packages/pydantic/_internal/_fields.py", line 122, in collect_model_fields type_hints = get_cls_type_hints_lenient(cls, types_namespace) File "/home/louis/miniconda3/envs/tubeulator/lib/python3.10/site-packages/pydantic/_internal/_typing_extra.py", line 212, in get_cls_type_hints_lenient hints[name] = eval_type_lenient(value, globalns, localns) File "/home/louis/miniconda3/envs/tubeulator/lib/python3.10/site-packages/pydantic/_internal/_typing_extra.py", line 224, in eval_type_lenient return eval_type_backport(value, globalns, localns) File "/home/louis/miniconda3/envs/tubeulator/lib/python3.10/site-packages/pydantic/_internal/_typing_extra.py", line 240, in eval_type_backport return typin ... (truncated) ...
Stack trace
error.txt
Error Message ------------- >> from tubeulator.generated.Journey import Identifier >> Identifier.model_validate({}) Identifier(Id=None, Name=None, Uri=None, FullName=None, Type=None, Crowding=None, RouteType=None, Status=None) >> Identifier.model_validate({"crowding": {"passengerFlows": [], "trainLoadings": []}}) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/louis/miniconda3/envs/tubeulator/lib/python3.10/site-packages/pydantic/main.py", line 509, in model_validate return cls.__pydantic_validator__.validate_python( pydantic_core._pydantic_core.ValidationError: 1 validation error for Identifier crowding Input should be None [type=none_required, input_value={}, input_type=dict] For further information visit https://errors.pydantic.dev/2.6/v/none_required

Minimal Reproduction

repro.py
from __future__ import annotations from pydantic import BaseModel, Field class Aaa(BaseModel): b: str = None class X(BaseModel): Aaa: Aaa = Field(None) # This crashes # Aaa: "Aaa" = Field(None) # Likewise # Aaa: Aaa = None # This is fine

Environment

  • Python: 3.10
  • Pydantic: 2

What Broke

Application crashes during model initialization due to type evaluation errors.

Why It Broke

Using a default Field crashes when the type annotation references a class of the same name as the field

Fix Options (Details)

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

pip install pydantic==1.10.14

When NOT to use: This fix is not applicable when field names do not clash with type annotations.

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

Option D — Guard side-effects with OnceOnly Guardrail for side-effects

Mitigate duplicate external side-effects under retries/timeouts/agent loops by gating the operation before calling external systems.

  • Place OnceOnly between your code/agent and real side-effects (Stripe, emails, CRM, APIs).
  • Use a stable key per side-effect (e.g., customer_id + action + idempotency_key).
  • Fail-safe: configure fail-open vs fail-closed based on blast radius and spend risk.
Show example snippet (optional)
onceonly.py
from onceonly import OnceOnly import os once = OnceOnly(api_key=os.environ["ONCEONLY_API_KEY"], fail_open=True) # Stable idempotency key per real side-effect. # Use a request id / job id / webhook delivery id / Stripe event id, etc. event_id = "evt_..." # replace key = f"stripe:webhook:{event_id}" res = once.check_lock(key=key, ttl=3600) if res.duplicate: return {"status": "already_processed"} # Safe to execute the side-effect exactly once. handle_event(event_id)

See OnceOnly SDK

When NOT to use: Do not use this to hide logic bugs or data corruption. Use it to block duplicate external side-effects and enforce tool permissions/spend caps.

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

First fixed release: 1.10.14

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 when field names do not clash with type annotations.
  • Do not use this to hide logic bugs or data corruption. Use it to block duplicate external side-effects and enforce tool permissions/spend caps.

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

Related Issues

No related fixes found.

Sources

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