Jump to solution
Verify

The Fix

pip install pydantic==2.12.5

Based on closed pydantic/pydantic issue #12503 · PR/commit linked

Jump to Verify Open PR/Commit
@@ -1110,6 +1110,10 @@ def match_type(self, obj: Any) -> core_schema.CoreSchema: # noqa: C901 elif is_typeddict(obj): return self._typed_dict_schema(obj, None) + elif inspect.isclass(obj) and issubclass(obj, Enum): + # NOTE: this must come before the `is_namedtuple()` check as enums values + # can be namedtuples:
repro.py
# src/test.py from enum import Enum from typing import NamedTuple from pydantic import BaseModel class _Something(NamedTuple): content: str class MyEnum(_Something, Enum): FOO = "foo" class MyModel(BaseModel): s: MyEnum MyModel(s=MyEnum.FOO)
verify
Re-run: python src/test.py
fix.md
Option A — Upgrade to fixed release\npip install pydantic==2.12.5\nWhen NOT to use: This fix should not be used if the Enum does not derive from NamedTuple.\n\n

Why This Fix Works in Production

  • Trigger: $ python src/test.py
  • Mechanism: Pydantic rejected instances of Enum with NamedTuple values due to type matching issues
  • Why the fix works: Fix support for enums with NamedTuple as values, resolving the issue where Pydantic rejected instances of the Enum as valid values. (first fixed release: 2.12.5).
Production impact:
  • If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).

Why This Breaks in Prod

  • Shows up under Python 3.13 in real deployments (not just unit tests).
  • Pydantic rejected instances of Enum with NamedTuple values due to type matching issues
  • Surfaces as: $ python src/test.py

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 I am using a custom class as branches of an Enum; And I would like to specify a model's property to be of type this Enum. However, pydantic rejects instances of t”
Issue thread · issue description · source

Failure Signature (Search String)

  • $ python src/test.py

Error Message

Stack trace
error.txt
Error Message ------------- $ python src/test.py Traceback (most recent call last): File "/app/src/yolo.py", line 18, in <module> MyModel(s=MyEnum.FOO) ~~~~~~~^^^^^^^^^^^^^^ File "/app/.venv/lib/python3.13/site-packages/pydantic/main.py", line 253, in __init__ validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self) File "/usr/local/lib/python3.13/enum.py", line 726, in __call__ return cls.__new__(cls, value) ~~~~~~~~~~~^^^^^^^^^^^^ File "/usr/local/lib/python3.13/enum.py", line 1203, in __new__ raise ve_exc ValueError: 'foo' is not a valid MyEnum

Minimal Reproduction

repro.py
# src/test.py from enum import Enum from typing import NamedTuple from pydantic import BaseModel class _Something(NamedTuple): content: str class MyEnum(_Something, Enum): FOO = "foo" class MyModel(BaseModel): s: MyEnum MyModel(s=MyEnum.FOO)

Environment

  • Python: 3.13
  • Pydantic: 2

What Broke

Instances of Enum were not accepted, causing validation errors in models.

Why It Broke

Pydantic rejected instances of Enum with NamedTuple values due to type matching issues

Fix Options (Details)

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

pip install pydantic==2.12.5

When NOT to use: This fix should not be used if the Enum does not derive from NamedTuple.

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

First fixed release: 2.12.5

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 used if the Enum does not derive from NamedTuple.

Verify Fix

verify
Re-run: python src/test.py

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

Related Issues

No related fixes found.

Sources

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