$ the-wire · showcase
Pydantic calls enum constructors in both validation modes
By RepoJournal · Filed · About FastAPI & Pydantic · Composed from the cited sources · methodology
Pydantic now invokes the enum class constructor during validation in both the Python and JSON validation paths, closing a gap left by an earlier pydantic-core change.
Pydantic merged a fix for enum validation that restores constructor invocation in both validation modes [1]. When the change in pydantic-core never called the enum class at all, the `_missing_()` method had to be passed in manually as part of the core schema; a later pydantic-core PR altered that behavior, and this patch aligns pydantic with it [1]. The same commit lands as "Call enum constructors in both validation modes" [2].
For code that relies on custom enum `_missing_` handling, the consequence is that the enum class is now exercised during validation rather than only through a manually supplied core schema hook. This is a behavioral change in how enum values resolve in both Python and JSON validation modes [1].
Review any custom `Enum` subclasses that define `_missing_()` and verify that their resolution logic still returns what you expect under validation in both modes [1][2].
Action items
- → Test custom Enum `_missing_()` subclasses under both Python and JSON validation modes after this change pydantic/pydantic [plan]
References
- [1] Call enum constructors in both validation modes ↗ pydantic/pydantic
- [2] Call enum constructors in both validation modes (#13792) ↗ pydantic/pydantic