Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum construction from float worked in v2.6.4 but fails in v2.7.1 #9375

Open
1 task done
Idealcoder opened this issue May 2, 2024 · 1 comment
Open
1 task done
Labels
bug V2 Bug related to Pydantic V2
Milestone

Comments

@Idealcoder
Copy link

Initial Checks

  • I confirm that I'm using Pydantic V2

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

from enum import Enum

from pydantic import TypeAdapter

class MyEnum(Enum):
    A = 1
    B = 2

ta = TypeAdapter(MyEnum)

assert ta.validate_python(1.0) is MyEnum.A
assert ta.validate_python(2.0) is MyEnum.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

Python, Pydantic & OS Version

pydantic version: 2.6.4
        pydantic-core version: 2.16.3
          pydantic-core build: profile=release pgo=false
                 install path: {redacted}\site-packages\pydantic
               python version: 3.9.15 | packaged by conda-forge | (main, Nov 22 2022, 08:39:05) [MSC v.1929 64 bit (AMD64)]
                     platform: Windows-10-10.0.19045-SP0
             related packages: fastapi-0.106.0 mypy-1.0.1 pydantic-settings-2.2.1 typing_extensions-4.10.0
                       commit: unknown


             pydantic version: 2.7.1
        pydantic-core version: 2.18.2
          pydantic-core build: profile=release pgo=false
                 install path: {redacted}\site-packages\pydantic
               python version: 3.9.15 | packaged by conda-forge | (main, Nov 22 2022, 08:39:05) [MSC v.1929 64 bit (AMD64)]
                     platform: Windows-10-10.0.19045-SP0
             related packages: fastapi-0.106.0 mypy-1.0.1 pydantic-settings-2.2.1 typing_extensions-4.11.0
                       commit: unknown
@Idealcoder Idealcoder added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels May 2, 2024
@sydney-runkle
Copy link
Member

@Idealcoder,

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!

@sydney-runkle sydney-runkle added this to the 2.7 fixes milestone May 14, 2024
@sydney-runkle sydney-runkle removed the pending Awaiting a response / confirmation label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V2 Bug related to Pydantic V2
Projects
None yet
Development

No branches or pull requests

2 participants