Jump to solution
Verify

The Fix

pip install pydantic==1.10.15

Based on closed pydantic/pydantic issue #9007 · 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
@@ -126,10 +126,6 @@ def plugin(version: str) -> type[Plugin]: -class _DeferAnalysis(Exception): - pass -
repro.py
from pydantic import BaseModel class Foo(BaseModel): id: int | None class Bar(BaseModel): foo: Foo | None class Baz(Bar): name: str b = Bar(foo={"id": 1}) z = Baz(foo={"id": 1}, name="test") assert z.foo.id == 1 # needed an ignore before assert b.foo.id == 1 # type: ignore[union-attr]
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.15\nWhen NOT to use: This fix should not be used if the mypy plugin is not configured correctly.\n\n

Why This Fix Works in Production

  • Trigger: assert z.foo.id == 1 # needed an ignore before
  • Mechanism: Fix handling of optionals in mypy plugin, resolving issues with optional type checks after upgrading to v2.6.4.
  • Why the fix works: Fix handling of optionals in mypy plugin, resolving issues with optional type checks after upgrading to v2.6.4. (first fixed release: 1.10.15).
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.11 in real deployments (not just unit tests).
  • Production symptom (often without a traceback): assert z.foo.id == 1 # needed an ignore before

Proof / Evidence

Discussion

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

“Awesome! We'll get #9008 across the line before the 2.7.0b1 release, so this should be fixed soon!”
@sydney-runkle · 2024-03-15 · confirmation · source
“Can you share your mypy config? Are you using no_strict_optional = True? Also, what version of mypy are you using?”
@dmontagu · 2024-03-13 · source
“I am using mypy v1.9.0 and I am actually using strict_optional=true. Here is the whole config:”
@pengelsman7 · 2024-03-14 · source
“Thank you for that info @pengelsman7, I was able to confirm locally that #9008 seems to fix your issue”
@dmontagu · 2024-03-14 · source

Failure Signature (Search String)

  • assert z.foo.id == 1 # needed an ignore before
  • assert b.foo.id == 1 # type: ignore[union-attr]
Copy-friendly signature
signature.txt
Failure Signature ----------------- assert z.foo.id == 1 # needed an ignore before assert b.foo.id == 1 # type: ignore[union-attr]

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- assert z.foo.id == 1 # needed an ignore before assert b.foo.id == 1 # type: ignore[union-attr]

Minimal Reproduction

repro.py
from pydantic import BaseModel class Foo(BaseModel): id: int | None class Bar(BaseModel): foo: Foo | None class Baz(Bar): name: str b = Bar(foo={"id": 1}) z = Baz(foo={"id": 1}, name="test") assert z.foo.id == 1 # needed an ignore before assert b.foo.id == 1 # type: ignore[union-attr]

Environment

  • Python: 3.11
  • Pydantic: 2

What Broke

Users experienced incorrect type checking results when using optional attributes in models.

Fix Options (Details)

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

pip install pydantic==1.10.15

When NOT to use: This fix should not be used if the mypy plugin is not configured correctly.

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

First fixed release: 1.10.15

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 mypy plugin is not configured correctly.

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

Related Issues

No related fixes found.

Sources

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