The Fix
pip install pydantic==2.11.8
Based on closed pydantic/pydantic issue #12105 · 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%.
@@ -979,11 +979,8 @@ def __getattr__(self, item: str) -> Any:
pydantic_extra = None
- if pydantic_extra:
- try:
- return pydantic_extra[item]
import pytest
from pydantic import BaseModel, ConfigDict
class A:
pass
class B(BaseModel):
model_config = ConfigDict(extra="allow")
@property
def y(self):
return A().x # this attribute does not exist
def test_attribute_error_with_no_extra():
with pytest.raises(AttributeError, match=f"'{A.__name__}' object has no attribute 'x'"):
B().y
def test_attribute_error_with_extra():
with pytest.raises(AttributeError, match=f"'{A.__name__}' object has no attribute 'x'"):
B(random_extra="some value").y
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==2.11.8\nWhen NOT to use: Do not apply this fix if the behavior of pydantic_extra needs to remain unchanged.\n\n
Why This Fix Works in Production
- Trigger: >> B().y
- Mechanism: The __getattr__ method in BaseModel does not handle AttributeError correctly when pydantic_extra is set
- Why the fix works: Fixes the behavior of `__getattr__()` in Pydantic models when a property raises an `AttributeError` and extra values are present. (first fixed release: 2.11.8).
- 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.13 in real deployments (not just unit tests).
- The __getattr__ method in BaseModel does not handle AttributeError correctly when pydantic_extra is set
- Surfaces as: >> B().y
Proof / Evidence
- GitHub issue: #12105
- Fix PR: https://github.com/pydantic/pydantic/pull/12106
- First fixed release: 2.11.8
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.40
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“PydanticAI Github Bot Found 1 issues similar to this one: 1. "https://github.com/pydantic/pydantic/issues/9070" (95% similar)”
Failure Signature (Search String)
- >> B().y
Error Message
Stack trace
Error Message
-------------
>> B().y
Traceback (most recent call last):
File "<python-input-4>", line 1, in <module>
B().y
File "/Users/raspuchin/Desktop/src/pydantic_bug/lib/python3.13/site-packages/pydantic/main.py", line 988, in __getattr__
return super().__getattribute__(item) # Raises AttributeError if appropriate
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "<python-input-2>", line 5, in y
return A().x # x does not exist
^^^^^
AttributeError: 'A' object has no attribute 'x'
Stack trace
Error Message
-------------
>> B(something='').y
Traceback (most recent call last):
File "/Users/raspuchin/Desktop/src/pydantic_bug/lib/python3.13/site-packages/pydantic/main.py", line 983, in __getattr__
return pydantic_extra[item]
~~~~~~~~~~~~~~^^^^^^
KeyError: 'y'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<python-input-5>", line 1, in <module>
B(something='').y
File "/Users/raspuchin/Desktop/src/pydantic_bug/lib/python3.13/site-packages/pydantic/main.py", line 985, in __getattr__
raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}') from exc
AttributeError: 'B' object has no attribute 'y'
Minimal Reproduction
import pytest
from pydantic import BaseModel, ConfigDict
class A:
pass
class B(BaseModel):
model_config = ConfigDict(extra="allow")
@property
def y(self):
return A().x # this attribute does not exist
def test_attribute_error_with_no_extra():
with pytest.raises(AttributeError, match=f"'{A.__name__}' object has no attribute 'x'"):
B().y
def test_attribute_error_with_extra():
with pytest.raises(AttributeError, match=f"'{A.__name__}' object has no attribute 'x'"):
B(random_extra="some value").y
Environment
- Python: 3.13
- Pydantic: 2
What Broke
Incorrect error handling leads to KeyError instead of AttributeError when accessing non-existent properties.
Why It Broke
The __getattr__ method in BaseModel does not handle AttributeError correctly when pydantic_extra is set
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.11.8
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Option D — Guard side-effects with OnceOnly Guardrail for side-effects
Mitigate duplicate external side-effects under retries/timeouts/agent loops by gating the operation before calling external systems.
- Place OnceOnly between your code/agent and real side-effects (Stripe, emails, CRM, APIs).
- Use a stable key per side-effect (e.g., customer_id + action + idempotency_key).
- Fail-safe: configure fail-open vs fail-closed based on blast radius and spend risk.
Show example snippet (optional)
from onceonly import OnceOnly
import os
once = OnceOnly(api_key=os.environ["ONCEONLY_API_KEY"], fail_open=True)
# Stable idempotency key per real side-effect.
# Use a request id / job id / webhook delivery id / Stripe event id, etc.
event_id = "evt_..." # replace
key = f"stripe:webhook:{event_id}"
res = once.check_lock(key=key, ttl=3600)
if res.duplicate:
return {"status": "already_processed"}
# Safe to execute the side-effect exactly once.
handle_event(event_id)
Fix reference: https://github.com/pydantic/pydantic/pull/12106
First fixed release: 2.11.8
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not apply this fix if the behavior of pydantic_extra needs to remain unchanged.
- Do not use this to hide logic bugs or data corruption. Use it to block duplicate external side-effects and enforce tool permissions/spend caps.
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 |
|---|---|
| 2.11.8 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.