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%.
@@ -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)
+
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'>
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.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).
- 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
- GitHub issue: #9738
- Fix PR: https://github.com/pydantic/pydantic/pull/9787
- First fixed release: 2.8.1
- 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).
“@kwint, Thanks for reporting this”
“Hi @sydney-runkle, I'd be happy to tackle this issue!”
“This is blocking me a bit so I gave it shot my self. Hope I didn't step on your toes @akshatvishu”
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
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 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
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
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.
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
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
| Version | Status |
|---|---|
| 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.