The Fix
pip install pydantic==2.9.2
Based on closed pydantic/pydantic issue #10411 · 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%.
@@ -120,7 +120,7 @@ def for_model(cls, bases: tuple[type[Any], ...], namespace: dict[str, Any], kwar
raw_annotations = namespace.get('__annotations__', {})
- if raw_annotations.get('model_config') and not config_dict_from_namespace:
+ if raw_annotations.get('model_config') and config_dict_from_namespace is None:
raise PydanticUserError(
from pydantic import BaseModel, ConfigDict
# this works
class Model(BaseModel):
model_config = {}
# this also works
class Model(BaseModel):
model_config: ConfigDict = {"str_max_length": 10}
# this raises PydanticUserError
class Model(BaseModel):
model_config: ConfigDict = {}
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.9.2\nWhen NOT to use: This fix should not be applied if model_config is intended to be used as a field name.\n\n
Why This Fix Works in Production
- Trigger: `PydanticUserError` raised when `model_config` has type annotation and is empty
- Mechanism: The logic incorrectly raises an error when model_config is empty but annotated
- Why the fix works: Fixes a PydanticUserError raised when model_config has a type annotation but is empty. (first fixed release: 2.9.2).
- 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 in real deployments (not just unit tests).
- The logic incorrectly raises an error when model_config is empty but annotated
- Surfaces as: `PydanticUserError` raised when `model_config` has type annotation and is empty
Proof / Evidence
- GitHub issue: #10411
- Fix PR: https://github.com/pydantic/pydantic/pull/10412
- First fixed release: 2.9.2
- 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.59
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“### Initial Checks - [X] I confirm that I'm using Pydantic V2 ### Description When model_config has a type annotation (model_config: ConfigDict) and is also empty, Pydantic raises a PydanticUserError. (I realize this case is a bit contrived”
Failure Signature (Search String)
- `PydanticUserError` raised when `model_config` has type annotation and is empty
Error Message
Stack trace
Error Message
-------------
`PydanticUserError` raised when `model_config` has type annotation and is empty
Minimal Reproduction
from pydantic import BaseModel, ConfigDict
# this works
class Model(BaseModel):
model_config = {}
# this also works
class Model(BaseModel):
model_config: ConfigDict = {"str_max_length": 10}
# this raises PydanticUserError
class Model(BaseModel):
model_config: ConfigDict = {}
Environment
- Python: 3.12
- Pydantic: 2
What Broke
Users encounter a PydanticUserError when using an empty model_config with type annotations.
Why It Broke
The logic incorrectly raises an error when model_config is empty but annotated
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.9.2
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/10412
First fixed release: 2.9.2
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if model_config is intended to be used as a field name.
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.9.2 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.