You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromenumimportEnumfrompydanticimportTypeAdapterclassMyEnum(Enum):
A=1B=2ta=TypeAdapter(MyEnum)
assertta.validate_python(1.0) isMyEnum.Aassertta.validate_python(2.0) isMyEnum.B# pydantic=2.6.4 passes validation# pydantic=2.7.1 fails validation## pydantic_core._pydantic_core.ValidationError: 1 validation error for enum[MyEnum]# Input should be 1, 2 or 3 [type=enum, input_value=1.0, input_type=float]# For further information visit https://errors.pydantic.dev/2.7/v/enum
Thanks for reporting this. Looks like a regression we should fix in 2.7.2. Adding this to the relevant milestone. Just got back form a week off, so I'll dive into more 2.7 fixes shortly!
Initial Checks
Description
Constructing an enum from a float worked in v2.6.4 but fails in v2.7.1.
Is this an intended change or a regression?
I see some changes around enum validation have been made #9064, pydantic/pydantic-core#1235 @samuelcolvin
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: