Enhancement: support Pydantic v1 and v2 at the same time
gotofritz opened this issue ยท 4 comments
Description
Pydantic v2 allows uses to use v1 models by importing them as from pydantic.v1 import BaseModel
.
This however breaks polyfactory, which will switch behaviour depending on the version of the pydantic installed, not on the version of the model class. Ideally, it each class would be checked independently
URL to code causing the issue
No response
MCVE
from pydantic.v1 import BaseModel
from polyfactory.factories.pydantic_factory import ModelFactory
class Duck(BaseModel):
noise: str
class FakeDuckFactory(ModelFactory[Duck]):
__model__ = Duck
produces
ConfigurationException: Model type Duck is not supported. To support it, register an appropriate base factory and subclass it for your factory.
Release Version
2.12.0
@gotofritz, thanks for pointing this out!
However, I don't think this is a bug since it's just not supported. I think this will count as a feature request and it should be possible to support this as well.
+1 on this request. This is preventing us from upgrading to pydantic v2 on many repositories (we have many services with distinct version of models which we can't upgrade all at once) . We're basically moving to other lib alternatives and having to rewrite tests because of this.
@gotofritz @albertferras-vrf this is included now :)
It still hasn't been released though. There are a few other pydantic related issues like #442 that I'd like to take care of before doing another release. You can expect the release in two weeks though :)
Thanks.