Jump to solution
Verify

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

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

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.”
@Viicos · 2024-11-28 · confirmation · source
“Minimal repro, without making use of FastAPI:”
@Viicos · 2024-11-25 · repro detail · source
“@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 · 2024-11-25 · source
“@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…”
@stt-mapa · 2024-11-28 · source

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

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

When NOT to use: Do not use this fix if the application relies on the previous behavior of schema generation.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use this fix if the application relies on the previous behavior of schema generation.

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