Jump to solution
Verify

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%.

Jump to Verify Open PR/Commit
@@ -321,6 +321,7 @@ def __init__( name: str, alias: str | None, + is_frozen: bool, has_dynamic_alias: bool, has_default: bool,
repro.py
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
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
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
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

  • 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

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.”
@sydney-runkle · 2024-07-22 · source

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
signature.txt
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.txt
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

repro.py
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.

When NOT to use: Do not use this fix if your application relies on mutable frozen fields for functionality.

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

Last verified: 2026-02-11. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use this fix if your application relies on mutable frozen fields for functionality.

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.

Related Issues

No related fixes found.

Sources

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