-
Notifications
You must be signed in to change notification settings - Fork 4
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
Incompatible with pydantic v2 #2
Comments
Yes, |
Pydantic v2 support added in version 0.5.0 |
Hi @romis2012, it seems like there are compatibility issues with The following code works with from pydantic import BaseModel
from pydantic_collections import BaseCollectionModel
class MyModel(BaseModel):
foo: str
class MyModelList(BaseCollectionModel[MyModel]):
pass
if __name__ == "__main__":
assert MyModelList([{"foo": "bar"}, {"foo": "baz"}]) When running this code in an environment using
Note that I found this error while trying to reproduce another error I have found when using pydantic collections with v2. I was trying to create a minimal environment to reproduce it and instead found this. I will let you know if/when I can reproduce the other error I am having. |
It seems like it was broken here but from the comment in that PR, I have a feeling that the setting of
|
Fixed in v0.5.1
Вторник, 22 августа 2023, 10:13 +03:00 от Matthew Elwell ***@***.***>:
Hi @romis2012 , it seems like there are compatibility issues with pydantic==2.2.1? Perhaps this is a pydantic issue rather than a pydantic-collection issue so please forgive me if so but, given the relevance of this issue, I figured I would raise it here first.
The following code works with pydantic==2.1.1 but not 2.2.1.
from pydantic import BaseModel
from pydantic_collections import BaseCollectionModel
class MyModel(BaseModel):
foo: str
class MyModelList(BaseCollectionModel[MyModel]):
pass
if __name__ == "__main__":
assert MyModelList([{"foo": "bar"}, {"foo": "baz"}])
When running this code in an environment using pydantic==2.2.1 I get the following exception:
Traceback (most recent call last):
File "/Users/matthewelwell/projects/sandbox/pydantic2collections/models.py", line 2, in <module>
from pydantic_collections import BaseCollectionModel
File "/Users/matthewelwell/projects/sandbox/pydantic2collections/.venv/lib/python3.11/site-packages/pydantic_collections/__init__.py", line 10, in <module>
from ._v2 import BaseCollectionModel, CollectionModelConfig
File "/Users/matthewelwell/projects/sandbox/pydantic2collections/.venv/lib/python3.11/site-packages/pydantic_collections/_v2.py", line 86, in <module>
class BaseCollectionModel(
File "/Users/matthewelwell/projects/sandbox/pydantic2collections/.venv/lib/python3.11/site-packages/pydantic/_internal/_model_construction.py", line 123, in __new__
cls: type[BaseModel] = super().__new__(mcs, cls_name, bases, namespace, **kwargs) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen abc>", line 106, in __new__
File "/Users/matthewelwell/projects/sandbox/pydantic2collections/.venv/lib/python3.11/site-packages/pydantic/root_model.py", line 50, in __init_subclass__
raise PydanticUserError(
pydantic.errors.PydanticUserError: `RootModel` does not support setting `model_config['extra']`
Note that I found this error while trying to reproduce another error I have found when using pydantic collections with v2. I was trying to create a minimal environment to reproduce it and instead found this. I will let you know if/when I can reproduce the other error I am having.
—
Reply to this email directly, view it on GitHub , or unsubscribe .
You are receiving this because you were mentioned. Message ID: <romis2012/pydantic-collections/issues/2/1687605324 @ github . com>
--
Роман Снегирев
|
pydantic.error_wrappers:ErrorWrapper
has been removed in V2The text was updated successfully, but these errors were encountered: