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

custom root types (apparently) not working well on 0.32.2 (pip version) #835

Closed
RobinDavid opened this issue Sep 26, 2019 · 7 comments
Closed
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@RobinDavid
Copy link

Dear all,

I am encountering an issue custom root data types.
I found to the issue #507 which has apparently been merged on July 6th. I am using the pydantic version from pip which is the 0.32.2 published on August 17th. Under this version the following snippet still produce '{"__root__": ["dog", "cat"]}' instead of '["dog", "cat"]'.

from typing import List
from pydantic import BaseModel

class Pets(BaseModel):
    __root__: List[str]

pets = Pets(__root__=['dog', 'cat'])
pets.json()
# '{"__root__": ["dog", "cat"]}'

Files modified by the issue seems to be present on the PyPI package thus I am wondering why it is still behaving like this ? It works perfectly fine on master, thus I am wondering if some changes that have been made in between might have "tampered" the custome root type behavior. Are you also encountering this issue ?

Best regards,
Robin

Infos:

  • OS: Debian
  • Python version: 3.7.3
  • Pydantic version: 0.32.2
@RobinDavid RobinDavid added the bug V1 Bug related to Pydantic V1.X label Sep 26, 2019
@koxudaxi
Copy link
Contributor

@RobinDavid
The custom root type behavior is correct in version: 0.32.2.
The version should return '{"__root__": ["dog", "cat"]}'

The master branch is a different code from version 0.32.2
The PR was merged into master for version 1.0
#752

The project prepares to publish version 1.0.
#576

@RobinDavid
Copy link
Author

Ok nice, I missed this PR merged 😃 !

Will there be other intermediate versions before the 1.0 ?

Feel free the close the issue if it is not relevant wrt open issues

@koxudaxi
Copy link
Contributor

Will there be other intermediate versions before the 1.0 ?

Nothing...

Fortunately, pip supports to install package from the git repo.
if you need the master version then, you can install packages with current commit hash.
However, please be careful. the master is not released 👀

$ pip install git+git://github.com/samuelcolvin/pydantic.git@6320d8ca7c66296ce3452fe7db48801a6bd17c4a

or you can write the same syntax in requirements.txt 😄

@RobinDavid
Copy link
Author

OK nice good to know! Thanks!

I have tried using the master of pydantic but I am using it with FastAPI (0.38.1) and I think there is some version incompatibilities between the two. When doing so I am having the following error:

File "/home/[...]/site-packages/fastapi/openapi/models.py", line 6
   from pydantic.types import UrlStr
ImportError: cannot import name 'UrlStr' from pydantic.types)

I think I will patiently wait 😄 . By the way thank you for the help on that 😉

@dmontagu
Copy link
Contributor

@RobinDavid yes there are probably serious incompatibilities between pydantic 1.0 and fastapi -- lots of breaking changes are going into 1.0 (that way we don't have to have more later!).

For what it's worth I'm also a heavy user of fastapi, and as soon as pydantic 1.0 is out, getting fastapi to work with it will be one of my top priorities!

@RobinDavid
Copy link
Author

Yes that makes sense. I am very much looking forward to it :)

@samuelcolvin
Copy link
Member

beta of v1 will be out this week.

alexdrydew pushed a commit to alexdrydew/pydantic that referenced this issue Dec 23, 2023
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

No branches or pull requests

4 participants