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%.
@@ -126,10 +126,6 @@ def plugin(version: str) -> type[Plugin]:
-class _DeferAnalysis(Exception):
- pass
-
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]
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
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).
- 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
- GitHub issue: #9007
- Fix PR: https://github.com/pydantic/pydantic/pull/9008
- First fixed release: 1.10.15
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.75
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.65
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!”
“Can you share your mypy config? Are you using no_strict_optional = True? Also, what version of mypy are you using?”
“I am using mypy v1.9.0 and I am actually using strict_optional=true. Here is the whole config:”
“Thank you for that info @pengelsman7, I was able to confirm locally that #9008 seems to fix your issue”
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
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 Message
-------------
assert z.foo.id == 1 # needed an ignore before
assert b.foo.id == 1 # type: ignore[union-attr]
Minimal Reproduction
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
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.
When NOT to Use This Fix
- This fix should not be used if the mypy plugin is not configured correctly.
Verify Fix
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
| Version | Status |
|---|---|
| 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.