The Fix
pip install pydantic==2.10.3
Based on closed pydantic/pydantic issue #10960 · 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%.
@@ -1009,24 +1009,36 @@ def dict_schema(self, schema: core_schema.DictSchema) -> JsonSchemaValue:
json_schema: JsonSchemaValue = {'type': 'object'}
- keys_schema = self.resolve_ref_schema(
- self.generate_inner(schema['keys_schema']).copy() if 'keys_schema' in schema else {}
- )
from enum import StrEnum
from typing import Annotated
from fastapi import FastAPI
from pydantic import BaseModel, Field
class PrimaryColor(StrEnum):
RED = 'red'
GREEN = 'green'
BLUE = 'blue'
class Color(BaseModel):
primary_color_values: dict[PrimaryColor, Annotated[int, Field(ge=0, le=255)]]
white = Color(primary_color_values={PrimaryColor.RED: 255, PrimaryColor.GREEN: 255, PrimaryColor.BLUE: 255})
app = FastAPI()
@app.post("/color")
def color(color: Color) -> None:
pass
print(app.openapi())
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.3\nWhen NOT to use: Do not use this fix if the application relies on the previous behavior of schema generation.\n\n
Why This Fix Works in Production
- Trigger: Problem generating OpenAPI schema for models with an enum as the key of a dict
- Mechanism: The JSON Schema reference for dict core schema keys was not resolved correctly
- Why the fix works: upstream changes in 2.10.3 address the mechanism above.
- 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 JSON Schema reference for dict core schema keys was not resolved correctly
- Production symptom (often without a traceback): Problem generating OpenAPI schema for models with an enum as the key of a dict
Proof / Evidence
- GitHub issue: #10960
- Fix PR: https://github.com/pydantic/pydantic/pull/10989
- First fixed release: 2.10.3
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.80
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.49
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Thanks @Martin19037, this is fixed in https://github.com/pydantic/pydantic/pull/10989.”
“Minimal repro, without making use of FastAPI:”
“@dmontagu, This feels related to the issue you reported last week re json schema customization. Just making this as a note to myself so I…”
“@sydney-runkle I have a slightly different example that produces the same runtime error, maybe this helps with testing: RuntimeError: Cannot update undefined schema for $ref=#/$defs/__main____RecordType-Output__1…”
Failure Signature (Search String)
- Problem generating OpenAPI schema for models with an enum as the key of a dict
- The code below used to work on 2.9.2, but it crashes on 2.10 with a message:
Copy-friendly signature
Failure Signature
-----------------
Problem generating OpenAPI schema for models with an enum as the key of a dict
The code below used to work on 2.9.2, but it crashes on 2.10 with a message:
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Problem generating OpenAPI schema for models with an enum as the key of a dict
The code below used to work on 2.9.2, but it crashes on 2.10 with a message:
Minimal Reproduction
from enum import StrEnum
from typing import Annotated
from fastapi import FastAPI
from pydantic import BaseModel, Field
class PrimaryColor(StrEnum):
RED = 'red'
GREEN = 'green'
BLUE = 'blue'
class Color(BaseModel):
primary_color_values: dict[PrimaryColor, Annotated[int, Field(ge=0, le=255)]]
white = Color(primary_color_values={PrimaryColor.RED: 255, PrimaryColor.GREEN: 255, PrimaryColor.BLUE: 255})
app = FastAPI()
@app.post("/color")
def color(color: Color) -> None:
pass
print(app.openapi())
Environment
- Python: 3.11
- Pydantic: 2
What Broke
The application crashes with a RuntimeError when generating OpenAPI schema.
Why It Broke
The JSON Schema reference for dict core schema keys was not resolved correctly
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.10.3
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/10989
First fixed release: 2.10.3
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if the application relies on the previous behavior of schema generation.
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.3 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.