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

BaseSetting Optional[conset(...)] not validated correctly #2320

Closed
3 tasks done
zoopp opened this issue Feb 5, 2021 · 1 comment · Fixed by #2321
Closed
3 tasks done

BaseSetting Optional[conset(...)] not validated correctly #2320

zoopp opened this issue Feb 5, 2021 · 1 comment · Fixed by #2321
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@zoopp
Copy link

zoopp commented Feb 5, 2021

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.7.3
            pydantic compiled: True
                 install path: /home/mihai/.virtualenvs/pydantic/lib/python3.9/site-packages/pydantic
               python version: 3.9.1 (default, Dec 13 2020, 11:55:53)  [GCC 10.2.0]
                     platform: Linux-5.10.12-3-ck-x86_64-with-glibc2.32
     optional deps. installed: []
from typing import Optional

from pydantic import BaseModel, BaseSettings, IPvAnyNetwork, conset


class InfoModelSet(BaseModel):
    network_segments: Optional[set[IPvAnyNetwork]]


class InfoModelConset(BaseModel):
    network_segments: Optional[conset(IPvAnyNetwork, min_items=1)]


class InfoSettingsSet(BaseSettings):
    network_segments: Optional[set[IPvAnyNetwork]]


class InfoSettingsConset(BaseSettings):
    network_segments: Optional[conset(IPvAnyNetwork, min_items=1)]


print(f"Info model set: {InfoModelSet()}")
print(f"Info model conset: {InfoModelConset()}")
print(f"Info settings set: {InfoSettingsSet()}")
print()
print(f"Info settings conset: {InfoSettingsConset()}")

Results in:

Info model set: network_segments=None
Info model conset: network_segments=None
Info settings set: network_segments=None

Traceback (most recent call last):
  File "/home/mihai/bug.py", line 25, in <module>
    print(f"Info settings conset: {InfoSettingsConset()}")
  File "pydantic/env_settings.py", line 34, in pydantic.env_settings.BaseSettings.__init__
  File "pydantic/main.py", line 362, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for InfoSettingsConset
network_segments
  value is not a valid set (type=type_error.set)

I would have expected the sample to pass without raising errors and network_segments of the InfoSettingsConset instance to be None.

@zoopp zoopp added the bug V1 Bug related to Pydantic V1.X label Feb 5, 2021
@PrettyWood
Copy link
Member

Hi @zoopp and thanks for reporting
You're absolutely right! Luckily the fix was trivial

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants