The Fix
Handles frozen fields on a per-field basis, addressing the issue where mypy does not show an error when attempting to mutate a frozen field.
Based on closed pydantic/pydantic issue #9923 · 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%.
@@ -321,6 +321,7 @@ def __init__(
name: str,
alias: str | None,
+ is_frozen: bool,
has_dynamic_alias: bool,
has_default: bool,
from pydantic import BaseModel, Field
class Foo(BaseModel):
a: int = Field(default=1, frozen=True)
foo = Foo()
foo.a = 2 # no mypy error, crashes at runtime
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Apply the official fix\nHandles frozen fields on a per-field basis, addressing the issue where mypy does not show an error when attempting to mutate a frozen field.\nWhen NOT to use: Do not use this fix if your application relies on mutable frozen fields for functionality.\n\n
Why This Fix Works in Production
- Trigger: no mypy error when attempting to mutate frozen field
- Mechanism: The mypy plugin does not enforce immutability for frozen fields in Pydantic models
- 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
- The mypy plugin does not enforce immutability for frozen fields in Pydantic models
- Production symptom (often without a traceback): no mypy error when attempting to mutate frozen field
Proof / Evidence
- GitHub issue: #9923
- Fix PR: https://github.com/pydantic/pydantic/pull/9935
- Reproduced locally: No (not executed)
- Last verified: 2026-02-11
- Confidence: 0.70
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.72
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Hmm, the plugin should definitely be handling this. Thanks for the bug report.”
Failure Signature (Search String)
- no mypy error when attempting to mutate frozen field
- when using the mypy pydantic plugin, it does not show an error when attempting to mutate a frozen field
Copy-friendly signature
Failure Signature
-----------------
no mypy error when attempting to mutate frozen field
when using the mypy pydantic plugin, it does not show an error when attempting to mutate a frozen field
Error Message
Signature-only (no traceback captured)
Error Message
-------------
no mypy error when attempting to mutate frozen field
when using the mypy pydantic plugin, it does not show an error when attempting to mutate a frozen field
Minimal Reproduction
from pydantic import BaseModel, Field
class Foo(BaseModel):
a: int = Field(default=1, frozen=True)
foo = Foo()
foo.a = 2 # no mypy error, crashes at runtime
Environment
- Pydantic: 2
What Broke
Attempting to mutate a frozen field leads to runtime crashes without prior mypy errors.
Why It Broke
The mypy plugin does not enforce immutability for frozen fields in Pydantic models
Fix Options (Details)
Option A — Apply the official fix
Handles frozen fields on a per-field basis, addressing the issue where mypy does not show an error when attempting to mutate a frozen field.
Fix reference: https://github.com/pydantic/pydantic/pull/9935
Last verified: 2026-02-11. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if your application relies on mutable frozen fields for functionality.
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.
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.