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

Not iterable error in optional lists constrained by unique items #4626

Closed
6 of 15 tasks
nuno-andre opened this issue Oct 16, 2022 · 1 comment
Closed
6 of 15 tasks

Not iterable error in optional lists constrained by unique items #4626

nuno-andre opened this issue Oct 16, 2022 · 1 comment
Labels
bug V1 Bug related to Pydantic V1.X unconfirmed Bug not yet confirmed as valid/applicable

Comments

@nuno-andre
Copy link
Contributor

Initial Checks

  • I have searched GitHub for a duplicate issue and I'm sure this is something new
  • I have searched Google & StackOverflow for a solution and couldn't find anything
  • I have read and followed the docs and still think this is a bug
  • I am confident that the issue is with pydantic (not my code, or another library in the ecosystem like FastAPI or mypy)

Description

unique_items validation breaks optional lists when None is passed as a value.

Example Code

from typing import Any, Optional
from pydantic import BaseModel, conlist

class Model(BaseModel):
    prop: Optional[conlist(Any, unique_items=True)]

m = Model(prop=None)

#> pydantic.error_wrappers.ValidationError: 1 validation error for Model
#> prop
#>   'NoneType' object is not iterable (type=type_error)

Python, Pydantic & OS Version

pydantic version: 2.0.0.dev0
install path: C:\repos_me\ppp\pydantic\pydantic
python version: 3.9.8 (tags/v3.9.8:bb3fdcf, Nov  5 2021, 20:48:33) [MSC v.1929 64 bit (AMD64)]
platform: Windows-10-10.0.19044
optional deps. installed: ['email-validator', 'typing-extensions']

Affected Components

@nuno-andre nuno-andre added bug V1 Bug related to Pydantic V1.X unconfirmed Bug not yet confirmed as valid/applicable labels Oct 16, 2022
@nuno-andre
Copy link
Contributor Author

Fixed by #4568

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X unconfirmed Bug not yet confirmed as valid/applicable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant