It seems like generating Json
fields in Pydantic (1.10) creates a bug. Trying the factory_use_construct=True
does not help as it provides a JsonWrapperValue
object which is not a valid Json
.
No response
from typing import Dict
from pydantic import Json, BaseModel
from polyfactory.factories.pydantic_factory import ModelFactory
class MyModel(BaseModel):
myfield: Json[Dict[str,str]]
class MyModelFactory(ModelFactory[MyModel]):
__model__ = MyModel
print(type(MyModelFactory.build(factory_use_construct=True).myfield))
# >> HAS INVALID TYPE
# <class '.JsonWrapperValue'>
MyModelFactory.build()
# >> RAISES EXCEPTION:
# E pydantic.error_wrappers.ValidationError: 1 validation error for MyModel
# E myfield
# E JSON object must be str, bytes or bytearray (type=type_error.json)
2.12.0
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too