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
Unexpected validation error with optional list field with unique_items check #4119
Comments
Shall I raise one PR to 1.9.X-fixes |
What happens on 1.8.2? |
There is no support for class Model(BaseModel):
foo: Optional[List[str]] = Field(None, unique_items=True)
Model(foo=['a','a','a'], bar=None) Won't raise any issues (duplicate items are there in the list) and class Model(BaseModel):
bar: conlist(str, unique_items=True) = Field(None)
Model(bar=['a','a','a']) Will raise an issue
ps: I need the support for |
Sorry, my bad. 🙈 Yes, pr against that branch please. |
Did this PR ever get made? If not, I'd be happy to create it. |
When using `unique_items` with an `Optional[List[T]]` field, the field validator would raise the following error if the field was not provided: > `'NoneType' object is not iterable (type=type_error)` Updating the validator to return `None` in these cases avoids the issue. Fixes pydantic#3957, pydantic#4050, pydantic#4119
When using `unique_items` with an `Optional[List[T]]` field, the field validator would raise the following error if the field was not provided: > `'NoneType' object is not iterable (type=type_error)` Updating the validator to return `None` in these cases avoids the issue. Fixes pydantic#3957, pydantic#4050, pydantic#4119
When using `unique_items` with an `Optional[List[T]]` field, the field validator would raise the following error if the field was not provided: > `'NoneType' object is not iterable (type=type_error)` Updating the validator to return `None` in these cases avoids the issue. Fixes pydantic#3957, pydantic#4050, pydantic#4119
The keyword |
Checks
Bug
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:Related discussion: #4050
Test case
Fix
Update the
unique_items_validator
function code to.Tested this and ran all test cases and successfully passed.
Please verify.
Cc: @samuelcolvin
The text was updated successfully, but these errors were encountered: