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

Missing downwards compatibility and bug with custom root types #2449

Closed
camold opened this issue Mar 2, 2021 · 0 comments · Fixed by #2451
Closed

Missing downwards compatibility and bug with custom root types #2449

camold opened this issue Mar 2, 2021 · 0 comments · Fixed by #2451
Labels
bug V1 Bug related to Pydantic V1.X
Milestone

Comments

@camold
Copy link

camold commented Mar 2, 2021

from typing import Generic
from typing import TypeVar
from typing import List
from pydantic.generics import GenericModel
from pydantic import BaseModel

T = TypeVar("T")
class BaseList(GenericModel, Generic[T]):
     __root__: List[T]

class Test(BaseModel):
     mylist: BaseList[int]

Test(mylist=[1,2,3,4])
# Test(mylist=BaseList[int](__root__=[1, 2, 3, 4]))

Test(mylist=BaseList[int](__root__=[1,2,3,4]))
# ---------------------------------------------------------------------------
# ValidationError                           Traceback (most recent call last)
# <ipython-input-10-c373af038c5b> in <module>
# ----> 1 Test(mylist=BaseList[int](__root__=[1,2,3,4]))
# 
# /usr/local/lib/python3.8/dist-packages/pydantic/main.cpython-38-x86_64-linux-gnu.so in pydantic.main.BaseModel.__init__()
# 
# ValidationError: 1 validation error for Test
# mylist -> __root__
#   value is not a valid list (type=type_error.list)

Certainly no error with pydantic 1.6.1 (I tested this locally).
Probably also no errors with versions <1.8 because we have automatic tests in place with the newest package versions and these tests only fired yesterday.

On a first glance the documentation does not seem to have changed - so I assume also the behaviour should not have changed with the 1.8 release. See https://pydantic-docs.helpmanual.io/usage/models/#generic-models and
https://pydantic-docs.helpmanual.io/usage/models/#custom-root-types

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

             pydantic version: 1.8
            pydantic compiled: True
                 install path: /usr/local/lib/python3.8/dist-packages/pydantic
               python version: 3.8.0 (default, Oct 28 2019, 16:14:01)  [GCC 8.3.0]
                     platform: Linux-5.4.0-62-generic-x86_64-with-glibc2.27
     optional deps. installed: ['devtools', 'email-validator', 'typing-extensions']
...
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