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
Maxlen property always set to None, when deque item type is provided. #6581
Comments
Some more cases:
So it seems that it is validation issue on model creation only. I do not know the codebase here but potentially: |
Thanks @maciekglowka for this issue 🙏 As you may know, I've checked your first example code on V2, all of them returning Same for you second example. In from collections import deque
from typing import Deque
from typing_extensions import Annotated
from pydantic import BaseModel, ConfigDict, Field
class D(BaseModel):
q: Annotated[Deque[int], Field(deque(maxlen=10), max_length=10)]
model_config = ConfigDict(validate_assignment=True)
d = D()
d.q = deque([1] * 25) Note: We still accept bug fixes on |
Thanks for checking. |
@hramezani I've done a very simple fix (PR passes tests) - I am just rewriting the single attribute. Perhaps the rewrite should be less manual? But I am not really sure what happens under the hood in Pydantic. |
Fixed in 2aaddf6 |
Initial Checks
Description
The
maxlen
property of thedeque
field seems to be set toNone
when the queue item type is provided.In the example below I first create an untyped deque and upon instancing everything goes well - the
maxlen
is set to15
.However when the model definitions is more specific:
deque[int]
orDeque[int]
then themaxlen
value cannot be set.Example Code
Python, Pydantic & OS Version
Affected Components
.dict()
and.json()
construct()
, pickling, private attributes, ORM modeSelected Assignee: @davidhewitt
The text was updated successfully, but these errors were encountered: