Open li-dennis opened 6 months ago
hi @li-dennis - i can reproduce this, thank you for the issue!
we'll get this looked at
can you share your version of pydantic
please?
sure -- pydantic==2.6.3
. thanks for the prompt response!!
hi @li-dennis - i can reproduce this, thank you for the issue!
we'll get this looked at
can you share your version of
pydantic
please?
For the time being, i've created a new custom serializer to handle this, but it's far from ergonomic.
class Pydantic2JsonSerializer(JSONSerializer, Generic[PydanticModel]):
def dumps(self, data: PydanticModel) -> bytes:
result = data.model_dump_json(indent=2).encode("utf-8")
return result
def loads(self, blob: bytes) -> str:
return json.loads(blob.decode("utf-8"))
As it seems like, in serializers.py, only pydantic v1 is supported
if HAS_PYDANTIC_V2:
import pydantic.v1 as pydantic
from pydantic.v1 import BaseModel
from pydantic.v1.json import pydantic_encoder
else:
import pydantic
from pydantic import BaseModel
from pydantic.json import pydantic_encoder
hi @li-dennis - apologies for the delayed response!
lately we've been working on prefect 3.x which has native pydantic 2 support, so if you now pip install -U prefect --pre
your original example should work.
Do you want to keep this issue open for 2.x versions (where we do not plan to use pydantic 2 internals) or close it since the behavior is tested and working in 3.x?
First check
Bug summary
I am trying to turn on result persistence with 'json' as the default serializer. As I understand from the docs, the json serializer supports pydantic models
And looking through issues, it looks like prefect supports pydantic v1 and v2 https://github.com/PrefectHQ/prefect/issues/10145#issuecomment-1791675801
I have tried to enable json serialization for all flows/tasks for debugging purposes, but I quickly run into errors
Reproduction