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

Base64Bytes field doesn't raises validation error for min_length constraint #9251

Open
1 task done
kirillklimenko opened this issue Apr 15, 2024 · 2 comments · May be fixed by #9263
Open
1 task done

Base64Bytes field doesn't raises validation error for min_length constraint #9251

kirillklimenko opened this issue Apr 15, 2024 · 2 comments · May be fixed by #9263
Labels
bug V2 Bug related to Pydantic V2 good first issue help wanted Pull Request welcome

Comments

@kirillklimenko
Copy link

kirillklimenko commented Apr 15, 2024

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

The validation should raise an error due to the minimum length constraint set for the data field in the Test model. However, no validation error is raised even though the data field is empty.

Expected Behavior:

Passing empty data for the data field should raise a validation error due to the minimum length constraint set in the Test model.

Actual Behavior:

No validation error is raised when passing empty data for the data field.

Steps to Reproduce:

Define the provided models in a Pydantic-based Python script.
Attempt to validate input data where the data field is empty.
Notice that no validation error is raised even though the data field does not meet the minimum length constraint.
Additional Information:
This behavior was observed in Pydantic version 2.6.4.

Example Code

from pydantic import Base64Bytes, BaseModel, Field


class Test(BaseModel):
    data: Base64Bytes = Field(min_length=10)


test = Test(data=b"")  # no validation error

Python, Pydantic & OS Version

pydantic version: 2.6.4
pydantic-core version: 2.16.3
pydantic-core build: profile=release pgo=true
python version: 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
platform: Windows-10-10.0.22631-SP0
@kirillklimenko kirillklimenko added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Apr 15, 2024
@ShahriyarR
Copy link
Contributor

The same behavior is true for versions:

$ pip freeze | grep pydantic
pydantic==2.7.0
pydantic_core==2.18.1

@sydney-runkle sydney-runkle added help wanted Pull Request welcome good first issue and removed pending Awaiting a response / confirmation labels Apr 16, 2024
@sydney-runkle
Copy link
Member

@kirillklimenko,

Thanks for reporting, definitely a bug! PRs welcome with a fix!

@LouisGobert LouisGobert linked a pull request Apr 16, 2024 that will close this issue
5 tasks
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 good first issue help wanted Pull Request welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants