The Fix
pip install pydantic==2.6.1
Based on closed pydantic/pydantic issue #9017 · 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%.
@@ -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:
python -c "import pydantic.version; print(pydantic.version.version_info())"
pydantic version: 2.6.3
pydantic-core version: 2.16.3
pydantic-core build: profile=release pgo=true
install path: /Users/samduke/Development/tado-playground/hub_rpi/.venv/lib/python3.11/site-packages/pydantic
python version: 3.11.8 (main, Feb 6 2024, 21:21:21) [Clang 15.0.0 (clang-1500.1.0.2.5)]
platform: macOS-14.1-arm64-arm-64bit
related packages: typing_extensions-4.10.0 mypy-1.8.0
commit: unknown
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.6.1\nWhen NOT to use: This fix should not be applied if backward compatibility with existing code that relies on dynamic attribute setting is required.\n\nOption C — Workaround\nAdding an `@no_type_check` decorator to setattr:\nWhen NOT to use: This fix should not be applied if backward compatibility with existing code that relies on dynamic attribute setting is required.\n\n
Why This Fix Works in Production
- Trigger: mypy doesn't complain about non-existent attributes when setting
- Mechanism: The mypy plugin does not enforce type safety for setting non-existent attributes in Pydantic's BaseModel
- Why the fix works: Fixes the type-safety of attribute access in Pydantic's BaseModel, ensuring that non-existent attributes raise errors when set. (first fixed release: 2.6.1).
- 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.11 in real deployments (not just unit tests).
- The mypy plugin does not enforce type safety for setting non-existent attributes in Pydantic's BaseModel
- Production symptom (often without a traceback): mypy doesn't complain about non-existent attributes when setting
Proof / Evidence
- GitHub issue: #9017
- Fix PR: https://github.com/pydantic/pydantic/pull/8651
- First fixed release: 2.6.1
- 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.55
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Hum, are you certain this is an issue on latest? I believe this was fixed in https://github.com/pydantic/pydantic/pull/8651/”
“Closing for now, as I believe this is fixed on main and will be in 2.7.0b1. Feel free to ping me if you run a…”
“Workaround: Adding an @no_type_check decorator to setattr:”
Failure Signature (Search String)
- mypy doesn't complain about non-existent attributes when setting
- myblah.sdlkjdshljkdsj = "wekjhe" <<< # does not generate an error
Copy-friendly signature
Failure Signature
-----------------
mypy doesn't complain about non-existent attributes when setting
myblah.sdlkjdshljkdsj = "wekjhe" <<< # does not generate an error
Error Message
Signature-only (no traceback captured)
Error Message
-------------
mypy doesn't complain about non-existent attributes when setting
myblah.sdlkjdshljkdsj = "wekjhe" <<< # does not generate an error
Minimal Reproduction
python -c "import pydantic.version; print(pydantic.version.version_info())"
pydantic version: 2.6.3
pydantic-core version: 2.16.3
pydantic-core build: profile=release pgo=true
install path: /Users/samduke/Development/tado-playground/hub_rpi/.venv/lib/python3.11/site-packages/pydantic
python version: 3.11.8 (main, Feb 6 2024, 21:21:21) [Clang 15.0.0 (clang-1500.1.0.2.5)]
platform: macOS-14.1-arm64-arm-64bit
related packages: typing_extensions-4.10.0 mypy-1.8.0
commit: unknown
Environment
- Python: 3.11
- Pydantic: 2
What Broke
Developers can set non-existent attributes without receiving any type errors, leading to potential runtime issues.
Why It Broke
The mypy plugin does not enforce type safety for setting non-existent attributes in Pydantic's BaseModel
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.6.1
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Option C — Workaround Temporary workaround
Adding an `@no_type_check` decorator to setattr:
Use only if you cannot change versions today. Treat this as a stopgap and remove once upgraded.
Fix reference: https://github.com/pydantic/pydantic/pull/8651
First fixed release: 2.6.1
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if backward compatibility with existing code that relies on dynamic attribute setting is required.
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.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.