Jump to solution
Verify

The Fix

pip install pydantic==1.10.14

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

Production note: This usually shows up under retries/timeouts. Treat it as a side-effect risk until you can verify behavior with a canary + real traffic.

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 pydantic import BaseModel from typing import List, Optional class RulesSource(BaseModel): StatelessRulesAndCustomActions: Optional["StatelessRulesAndCustomActions"] = None class StatelessRulesAndCustomActions(BaseModel): StatelessRules: Optional[List["StatelessRule"]] = None class StatelessRule(BaseModel): pass def test_the_bug(): # Create instances of the classes to trigger type checking rules_source = RulesSource(StatelessRulesAndCustomActions=StatelessRulesAndCustomActions(StatelessRules=[StatelessRule()])) ============================================================================================= FAILURES ============================================================================================= ___________________________________________________________________________________________ test_the_bug ___________________________________________________________________________________________ def test_the_bug(): # Create instances of the classes to trigger type checking rules_source = RulesSource(StatelessRulesAndCustomActions=StatelessRulesAndCustomActions(StatelessRules=[StatelessRule()])) E pydantic_core._pydantic_core.ValidationError: 1 validation error for RulesSource E StatelessRulesAndCustomActions E Input should be None [type=none_required, input_value=StatelessRulesAndCustomAc...Rules=[StatelessRule()]), input_type=StatelessRulesAndCustomActions] E For further information visit https://errors.pydantic.dev/2.7/v/none_required
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 should not be applied if the model structure is intentionally designed to allow such collisions.\n\n

Why This Fix Works in Production

  • Trigger: from pydantic import BaseModel
  • Mechanism: Namespace collision occurs when a class property shares a name with another class and is defined as Optional
  • Why the fix works: Explicitly raises an error if field names clash with types, addressing potential namespace collisions in Pydantic models. (first fixed release: 1.10.14).
Production impact:
  • If left unfixed, retries/timeouts can trigger duplicate external side-effects (double charges, duplicate emails, repeated writes).

Why This Breaks in Prod

  • Shows up under Python 3.12 in real deployments (not just unit tests).
  • Namespace collision occurs when a class property shares a name with another class and is defined as Optional
  • Surfaces as: from pydantic import BaseModel

Proof / Evidence

Discussion

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

“Closing as a duplicate, based on the issues that @Viicos mentioned above. Thanks!”
@sydney-runkle · 2024-05-16 · confirmation · source
“Not sure, might need to double check, but I think this comes from what I described here: https://github.com/pydantic/pydantic/pull/8243#issuecomment-1831900199”
@Viicos · 2024-05-16 · source
“Since Optional[...] is shorthand for Union[..., None] I think that it does. On this same train, now that Union types are a thing in Py3.12,…”
@jrkarnes · 2024-05-16 · source
“This seems to be the same issue as: https://github.com/pydantic/pydantic/issues/7327, https://github.com/pydantic/pydantic/issues/8240, https://github.com/pydantic/pydantic/issues/7309 (see https://github.com/pydantic/pydantic/issues/6646#issuecomment-16339703”
@Viicos · 2024-05-03 · source

Failure Signature (Search String)

  • from pydantic import BaseModel

Error Message

Stack trace
error.txt
Error Message ------------- from pydantic import BaseModel from typing import List, Optional class RulesSource(BaseModel): StatelessRulesAndCustomActions: Optional["StatelessRulesAndCustomActions"] = None class StatelessRulesAndCustomActions(BaseModel): StatelessRules: Optional[List["StatelessRule"]] = None class StatelessRule(BaseModel): pass def test_the_bug(): # Create instances of the classes to trigger type checking rules_source = RulesSource(StatelessRulesAndCustomActions=StatelessRulesAndCustomActions(StatelessRules=[StatelessRule()])) ============================================================================================= FAILURES ============================================================================================= ___________________________________________________________________________________________ test_the_bug ___________________________________________________________________________________________ def test_the_bug(): # Create instances of the classes to trigger type checking rules_source = RulesSource(StatelessRulesAndCustomActions=StatelessRulesAndCustomActions(StatelessRules=[StatelessRule()])) E pydantic_core._pydantic_core.ValidationError: 1 validation error for RulesSource E StatelessRulesAndCustomActions E Input should be None [type=none_required, input_value=StatelessRulesAndCustomAc...Rules=[StatelessRule()]), input_ ... (truncated) ...

Minimal Reproduction

repro.py
from pydantic import BaseModel from typing import List, Optional class RulesSource(BaseModel): StatelessRulesAndCustomActions: Optional["StatelessRulesAndCustomActions"] = None class StatelessRulesAndCustomActions(BaseModel): StatelessRules: Optional[List["StatelessRule"]] = None class StatelessRule(BaseModel): pass def test_the_bug(): # Create instances of the classes to trigger type checking rules_source = RulesSource(StatelessRulesAndCustomActions=StatelessRulesAndCustomActions(StatelessRules=[StatelessRule()])) ============================================================================================= FAILURES ============================================================================================= ___________________________________________________________________________________________ test_the_bug ___________________________________________________________________________________________ def test_the_bug(): # Create instances of the classes to trigger type checking rules_source = RulesSource(StatelessRulesAndCustomActions=StatelessRulesAndCustomActions(StatelessRules=[StatelessRule()])) E pydantic_core._pydantic_core.ValidationError: 1 validation error for RulesSource E StatelessRulesAndCustomActions E Input should be None [type=none_required, input_value=StatelessRulesAndCustomAc...Rules=[StatelessRule()]), input_type=StatelessRulesAndCustomActions] E For further information visit https://errors.pydantic.dev/2.7/v/none_required

Environment

  • Python: 3.12
  • Pydantic: 2

What Broke

Instances of the class fail to validate, leading to runtime errors during instantiation.

Why It Broke

Namespace collision occurs when a class property shares a name with another class and is defined as Optional

Fix Options (Details)

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

pip install pydantic==1.10.14

When NOT to use: This fix should not be applied if the model structure is intentionally designed to allow such collisions.

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/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 should not be applied if the model structure is intentionally designed to allow such collisions.

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.