Jump to solution
Verify

The Fix

pip install pydantic==2.6.1

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

Jump to Verify Open PR/Commit
@@ -733,6 +733,7 @@ def __deepcopy__(self: Model, memo: dict[int, Any] | None = None) -> Model: if not typing.TYPE_CHECKING: # We put `__getattr__` in a non-TYPE_CHECKING block because otherwise, mypy allows arbitrary attribute access + # The same goes for __setattr__ and __delattr__, see: https://github.com/pydantic/pydantic/issues/8643 def __getattr__(self, item: str) -> Any:
repro.py
from pydantic import BaseModel class Foo(BaseModel): some_field: int def patch_object(foo: Foo) -> None: # Ohoh, we got the field name wrong... foo.some_feeld = 42 foo = Foo(some_field=1) patch_object(foo) assert foo.some_field == 42
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==2.6.1\nWhen NOT to use: This fix is not suitable if strict type checking is not required.\n\n

Why This Fix Works in Production

  • Trigger: error: "Foo" has no attribute "some_feeld"; maybe "some_field"? [attr-defined]
  • Mechanism: The __setattr__ method in BaseModel accepts Any, compromising type safety
  • Why the fix works: Fixes the type-safety of attribute access in `BaseModel` by moving the `__setattr__` and `__delattr__` methods into a non-TYPE_CHECKING block. (first fixed release: 2.6.1).
Production impact:
  • If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).

Why This Breaks in Prod

  • Shows up under Python 3.12 in real deployments (not just unit tests).
  • The __setattr__ method in BaseModel accepts Any, compromising type safety
  • Surfaces as: error: "Foo" has no attribute "some_feeld"; maybe "some_field"? [attr-defined]

Proof / Evidence

Discussion

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

“> Update: PR welcome with a fix for this Great, thanks! > we don't think this change will be significantly breaking in any way :)”
@bluenote10 · 2024-01-26 · source
“@bluenote10, Thanks for reporting this”
@sydney-runkle · 2024-01-26 · source

Failure Signature (Search String)

  • error: "Foo" has no attribute "some_feeld"; maybe "some_field"? [attr-defined]

Error Message

Stack trace
error.txt
Error Message ------------- error: "Foo" has no attribute "some_feeld"; maybe "some_field"? [attr-defined]

Minimal Reproduction

repro.py
from pydantic import BaseModel class Foo(BaseModel): some_field: int def patch_object(foo: Foo) -> None: # Ohoh, we got the field name wrong... foo.some_feeld = 42 foo = Foo(some_field=1) patch_object(foo) assert foo.some_field == 42

Environment

  • Python: 3.12
  • Pydantic: 2

What Broke

Type checkers fail to catch incorrect attribute assignments, leading to runtime errors.

Why It Broke

The __setattr__ method in BaseModel accepts Any, compromising type safety

Fix Options (Details)

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

pip install pydantic==2.6.1

When NOT to use: This fix is not suitable if strict type checking is not required.

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

First fixed release: 2.6.1

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 is not suitable if strict type checking is not required.

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
2.6.1 Fixed

Related Issues

No related fixes found.

Sources

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