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

Add list constraints #27

Merged
merged 2 commits into from
Aug 1, 2024
Merged

Add list constraints #27

merged 2 commits into from
Aug 1, 2024

Conversation

shkangomelet
Copy link
Contributor

Hello again!
I found that pydantic constraints on list/string doesn't seem to work well if I define it in pydantic.Field.

from drf_pydantic import BaseModel
from pydantic import Field


class Test(BaseModel):
    test_list: list[float] = Field(default=5, title="test", max_length=3)
    test_str: str = Field(default="", max_length=3)


if __name__ == "__main__":
    print(Test(test_list= [1,2,3]).drf_serializer.__dict__)

This is my test code.

So, I refined this to work well on Field.
Moreover, pydantic/pydantic#8771 shows that this constraints also applies to list.

Many thanks!

Copy link

codecov bot commented Aug 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.87%. Comparing base (422bce9) to head (8557052).
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##              main      #27      +/-   ##
===========================================
- Coverage   100.00%   98.87%   -1.13%     
===========================================
  Files            5        5              
  Lines          173      178       +5     
===========================================
+ Hits           173      176       +3     
- Misses           0        2       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@georgebv georgebv merged commit e8b8e29 into georgebv:main Aug 1, 2024
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants