The Fix
pip install pydantic==2.10.0
Based on closed pydantic/pydantic issue #10853 · 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%.
@@ -152,6 +152,8 @@ def wrapped_model_post_init(self: BaseModel, context: Any, /) -> None:
)
+ cls.__pydantic_setattr_handlers__ = {}
+
cls.__pydantic_decorators__ = DecoratorInfos.build(cls)
import timeit
from pydantic import BaseModel
class MyObj(BaseModel):
name: str
value: int | None
if __name__ == "__main__":
my_obj = MyObj(name="a", value=1)
def set_obj(obj):
obj.value = 10
return obj
def instantiation():
return MyObj(name="a", value=1)
print(timeit.timeit("set_obj(my_obj)", globals=globals(), number=1000000))
print(timeit.timeit("instantiation()", globals=globals(), number=1000000))
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.10.0\nWhen NOT to use: This fix is not suitable if extensive validation checks are required for every attribute assignment.\n\n
Why This Fix Works in Production
- Trigger: Attribute assignment in models is significantly slower than instantiation, impacting performance.
- Mechanism: The __setattr__ method performs extensive checks, causing slow attribute assignment in Pydantic models
- Why the fix works: Improves the performance of `__setattr__` in Pydantic models by caching setter functions, making attribute assignment significantly faster. (first fixed release: 2.10.0).
- 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.12.7 in real deployments (not just unit tests).
- The __setattr__ method performs extensive checks, causing slow attribute assignment in Pydantic models
- Production symptom (often without a traceback): Attribute assignment in models is significantly slower than instantiation, impacting performance.
Proof / Evidence
- GitHub issue: #10853
- Fix PR: https://github.com/pydantic/pydantic/pull/10868
- First fixed release: 2.10.0
- 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.63
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Fixing this would be relatively straight forward https://github.com/pydantic/pydantic/pull/10868”
“Yes, I have also seen this”
Failure Signature (Search String)
- Attribute assignment in models is significantly slower than instantiation, impacting performance.
Copy-friendly signature
Failure Signature
-----------------
Attribute assignment in models is significantly slower than instantiation, impacting performance.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Attribute assignment in models is significantly slower than instantiation, impacting performance.
Minimal Reproduction
import timeit
from pydantic import BaseModel
class MyObj(BaseModel):
name: str
value: int | None
if __name__ == "__main__":
my_obj = MyObj(name="a", value=1)
def set_obj(obj):
obj.value = 10
return obj
def instantiation():
return MyObj(name="a", value=1)
print(timeit.timeit("set_obj(my_obj)", globals=globals(), number=1000000))
print(timeit.timeit("instantiation()", globals=globals(), number=1000000))
Environment
- Python: 3.12.7
- Pydantic: 2
What Broke
Attribute assignment in models is significantly slower than instantiation, impacting performance.
Why It Broke
The __setattr__ method performs extensive checks, causing slow attribute assignment in Pydantic models
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.10.0
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/10868
First fixed release: 2.10.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is not suitable if extensive validation checks are required for every attribute assignment.
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.10.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.