Jump to solution
Verify

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%.

Jump to Verify Open PR/Commit
@@ -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(
repro.py
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 = {}
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.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).
Production impact:
  • 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

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”
Issue thread · issue description · source

Failure Signature (Search String)

  • `PydanticUserError` raised when `model_config` has type annotation and is empty

Error Message

Stack trace
error.txt
Error Message ------------- `PydanticUserError` raised when `model_config` has type annotation and is empty

Minimal Reproduction

repro.py
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

When NOT to use: This fix should not be applied if model_config is intended to be used as a field name.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

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

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.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.