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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValidationError when converting Decimal('10000000000000000000') to int #7305

Closed
1 task done
gmagno opened this issue Aug 31, 2023 · 3 comments 路 Fixed by pydantic/pydantic-core#948
Closed
1 task done
Assignees
Labels
bug V2 Bug related to Pydantic V2 unconfirmed Bug not yet confirmed as valid/applicable

Comments

@gmagno
Copy link

gmagno commented Aug 31, 2023

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

Hello 馃憢 馃

Pydantic throws a ValidationError when converting a Decimal of an int to int. Not sure if this is the expected behavior.

from decimal import Decimal
from pydantic import BaseModel

class A(BaseModel):
    a: int

A(a=10000000000000000000)  # this works

A(a=Decimal('10000000000000000000'))  # this doesn't
ValidationError: 1 validation error for A
a
  Unable to parse input string as an integer, exceeded maximum size [type=int_parsing_size, input_value=Decimal('10000000000000000000'), input_type=Decimal]
    For further information visit https://errors.pydantic.dev/2.3/v/int_parsing_size

Example Code

from decimal import Decimal
from pydantic import BaseModel

class A(BaseModel):
    a: int

A(a=Decimal('10000000000000000000'))

Python, Pydantic & OS Version

pydantic version: 2.3.0
  pydantic-core version: 2.6.3
    pydantic-core build: profile=release pgo=true
            install path: ****/.venv/lib/python3.10/site-packages/pydantic
          python version: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
                platform: Linux-5.19.0-50-generic-x86_64-with-glibc2.35
optional deps. installed: ['typing-extensions']

Selected Assignee: @lig

@gmagno gmagno added bug V2 Bug related to Pydantic V2 unconfirmed Bug not yet confirmed as valid/applicable labels Aug 31, 2023
@adriangb
Copy link
Member

adriangb commented Sep 6, 2023

It looks like what's happening here is that the Decimal is getting converted to a float first and then trying to be pushed into a float64. We'll need to fix this on the pydantic-core side.

@adriangb
Copy link
Member

adriangb commented Sep 8, 2023

This will be fixed in the next release. Thank you for reporting it!

@gmagno
Copy link
Author

gmagno commented Sep 8, 2023

Thank you @adriangb, you guys are amazing 鉂わ笍

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 unconfirmed Bug not yet confirmed as valid/applicable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants