Skip to content

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

@nico00

Description

@nico00

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V2Bug related to Pydantic V2

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions