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

An appropriate model cannot be created when using the IntEnum type in Python with values greater than 1<<63. #9314

Open
1 task done
Jassy930 opened this issue Apr 25, 2024 · 2 comments
Labels
bug V2 Bug related to Pydantic V2
Milestone

Comments

@Jassy930
Copy link

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

An appropriate model cannot be created when using the IntEnum type in Python with values greater than 1<<63.
which is allowed in pydantic v1.

I suspect the reason might be due to Rust's i64 type restrictions not supporting larger integer values, but it indeed feels inconsistent when using IntEnum for bitwise tagging.

Example Code

from pydantic import BaseModel
from enum import IntEnum


class ColorEnum(IntEnum):
    RED = 1
    GREEN = 1 << 63
    BLUE = 1 << 64


class model(BaseModel):
    color: ColorEnum


print(ColorEnum.GREEN.name, ColorEnum.GREEN.value)
print(ColorEnum.BLUE.name, ColorEnum.BLUE.value)

model.model_validate({"color": ColorEnum.GREEN.value})
model.model_validate_json('{"color": 9223372036854775808}')

model.model_validate({"color": ColorEnum.BLUE.value})
model.model_validate_json('{"color": 18446744073709551616}')

Python, Pydantic & OS Version

pydantic version: 2.7.0
        pydantic-core version: 2.18.1
          pydantic-core build: profile=release pgo=true
                 install path: /opt/homebrew/lib/python3.12/site-packages/pydantic
               python version: 3.12.3 (main, Apr  9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)]
                     platform: macOS-14.4.1-arm64-arm-64bit
             related packages: typing_extensions-4.11.0
                       commit: unknown
@Jassy930 Jassy930 added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Apr 25, 2024
@Jassy930
Copy link
Author

And I did not find anything in the migration documentation or elsewhere to suggest that this is an intentional difference after the migration, perhaps something that could usefully be added to the migration documentation.

@sydney-runkle
Copy link
Member

@Jassy930,

Thanks for reporting this. Definitely doesn't seem intentional. Adding this to the 2.7 fixes milestone, as I think we could address this when we rewrite the int enum validator (hopefully soon).

@sydney-runkle sydney-runkle added this to the 2.7 fixes milestone Apr 28, 2024
@sydney-runkle sydney-runkle removed the pending Awaiting a response / confirmation label Apr 28, 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