Dear all,
I am encountering an issue custom root data types.
I found to the issue https://github.com/samuelcolvin/pydantic/issues/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:
@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
https://github.com/samuelcolvin/pydantic/pull/752
The project prepares to publish version 1.0.
https://github.com/samuelcolvin/pydantic/issues/576
Ok nice, I missed this PR merged :smiley: !
Will there be other intermediate versions before the 1.0 ?
Feel free the close the issue if it is not relevant wrt open issues
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 馃槃
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 :smile: . By the way thank you for the help on that :wink:
@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!
Yes that makes sense. I am very much looking forward to it :)
beta of v1 will be out this week.