Jump to solution
Verify

The Fix

pip install pydantic==2.8.1

Based on closed pydantic/pydantic issue #9738 · 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
@@ -1248,7 +1248,14 @@ def _literal_schema(self, literal_type: Any) -> CoreSchema: expected = _typing_extra.all_literal_values(literal_type) assert expected, f'literal "expected" cannot be empty, obj={literal_type}' - return core_schema.literal_schema(expected) + schema = core_schema.literal_schema(expected) +
repro.py
from enum import StrEnum, auto from typing import Literal from pydantic import BaseModel, ConfigDict, Field class MyEnum(StrEnum): FOO = auto() BAR = auto() class MyModel(BaseModel): model_config = ConfigDict(use_enum_values=True) enum_field: MyEnum = Field(default=MyEnum.FOO, validate_default=True) class MyModelLiteral(BaseModel): model_config = ConfigDict(use_enum_values=True) enum_field: Literal[MyEnum.FOO] = Field(default=MyEnum.FOO, validate_default=True) # default="foo" gives same result print(type(MyModel().enum_field)) # <class 'str'> print(type(MyModelLiteral().enum_field)) # <enum 'MyEnum'>
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.8.1\nWhen NOT to use: Do not apply this fix if the field type is not a Literal or if use_enum_values is not required.\n\n

Why This Fix Works in Production

  • Trigger: However, when the type of the Field is a Literal of that enum, the validate_default doesn't seem to work. See code below.
  • Mechanism: The validate_default flag does not function correctly for fields typed as Literal when use_enum_values is enabled
  • Why the fix works: Addresses the issue where validate_default has no effect when the attribute type is Literal. (first fixed release: 2.8.1).
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 validate_default flag does not function correctly for fields typed as Literal when use_enum_values is enabled
  • Production symptom (often without a traceback): However, when the type of the Field is a Literal of that enum, the validate_default doesn't seem to work. See code below.

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“@kwint, Thanks for reporting this”
@sydney-runkle · 2024-06-24 · source
“Hi @sydney-runkle, I'd be happy to tackle this issue!”
@akshatvishu · 2024-06-24 · source
“This is blocking me a bit so I gave it shot my self. Hope I didn't step on your toes @akshatvishu”
@kwint · 2024-06-28 · source

Failure Signature (Search String)

  • However, when the type of the Field is a Literal of that enum, the validate_default doesn't seem to work. See code below.
Copy-friendly signature
signature.txt
Failure Signature ----------------- However, when the type of the Field is a Literal of that enum, the validate_default doesn't seem to work. See code below.

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- However, when the type of the Field is a Literal of that enum, the validate_default doesn't seem to work. See code below.

Minimal Reproduction

repro.py
from enum import StrEnum, auto from typing import Literal from pydantic import BaseModel, ConfigDict, Field class MyEnum(StrEnum): FOO = auto() BAR = auto() class MyModel(BaseModel): model_config = ConfigDict(use_enum_values=True) enum_field: MyEnum = Field(default=MyEnum.FOO, validate_default=True) class MyModelLiteral(BaseModel): model_config = ConfigDict(use_enum_values=True) enum_field: Literal[MyEnum.FOO] = Field(default=MyEnum.FOO, validate_default=True) # default="foo" gives same result print(type(MyModel().enum_field)) # <class 'str'> print(type(MyModelLiteral().enum_field)) # <enum 'MyEnum'>

Environment

  • Python: 3.11
  • Pydantic: 2

What Broke

The application fails to validate default values for Literal fields, leading to unexpected types in runtime.

Why It Broke

The validate_default flag does not function correctly for fields typed as Literal when use_enum_values is enabled

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install pydantic==2.8.1

When NOT to use: Do not apply this fix if the field type is not a Literal or if use_enum_values is not required.

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/9787

First fixed release: 2.8.1

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 apply this fix if the field type is not a Literal or if use_enum_values is not required.

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.
  • Add a stress test that runs high-concurrency workloads and fails on thread dumps / blocked locks.
  • Enable watchdog dumps in prod (faulthandler, thread dump endpoint) to capture deadlocks quickly.

Version Compatibility Table

VersionStatus
2.8.1 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.