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

v2.7.0 Validation error if integer field is filled with string "00" #9227

Closed
1 task done
nico00 opened this issue Apr 12, 2024 · 4 comments · Fixed by pydantic/pydantic-core#1269
Closed
1 task done
Labels
bug V2 Bug related to Pydantic V2
Milestone

Comments

@nico00
Copy link

nico00 commented Apr 12, 2024

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

This seems to be a regression as v.2.6.4 was not affected by this problem.

Basically if you define a model with an integer field and fill it with string "00", you get the following error message:

pydantic_core._pydantic_core.ValidationError: 1 validation error for MyModel
id
  Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='00', input_type=str]
    For further information visit https://errors.pydantic.dev/2.7/v/int_parsing

The problem seems only to happen with multiple zeros (i.e. "00", "000", ...), other numeric strings work properly (e.g. "01", "0").

Example Code

from pydantic import BaseModel

class User(BaseModel):
    id: int = 0

s = User(id="01") # works
print(s)  

s = User(id="00") # fails
print(s)

Python, Pydantic & OS Version

pydantic version: 2.7.0
pydantic-core version: 2.18.1
@nico00 nico00 added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Apr 12, 2024
@sydney-runkle
Copy link
Member

@nico00,

Thanks for reporting this. @samuelcolvin, could you please take a look? I think this is likely related to the int parsing changes you worked on recently...

@sydney-runkle sydney-runkle added this to the 2.7 fixes milestone Apr 12, 2024
@samuelcolvin
Copy link
Member

Yup, good catch, I'll fix over the weekend.

Sorry for the trouble.

@samuelcolvin samuelcolvin removed the pending Awaiting a response / confirmation label Apr 13, 2024
@samuelcolvin
Copy link
Member

should be fixed in pydantic/pydantic-core#1269.

@sydney-runkle
Copy link
Member

Thanks @samuelcolvin for the quick turnaround!

We'll release this fix in a patch release early next week 👍

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

Successfully merging a pull request may close this issue.

3 participants