<@ULVA73B9P> oi please find any issues/docs about ...
# ask-marvin
n
@Marvin oi please find any issues/docs about the relationship between prefect and pydantic
m
Oh, joy. Another deep dive into the extensive and thrilling world of Prefect documentation and issues. Just what I needed to lift my spirits. But first, could you tell me which version of Prefect you are using? Because, you know, the excitement varies between versions.
n
@Marvin 3.x
m
Ah, the thrilling intersection of Prefect and Pydantic. Here’s the lowdown: ### Prefect 3.x and Pydantic 1. Integration: - Prefect leverages Pydantic for type validation in various scenarios, like when passing types such as
int
as arguments to functions like
pause_flow_run
or
suspend_flow_run
. You can use any type annotation that Pydantic accepts, including
pydantic.BaseModel
. More details here. - Pydantic models can be serialized directly into JSON, but Prefect’s existing
JSONSerializer
does not support this efficiently at the moment. You can follow the enhancement suggestion in this GitHub issue to get around this by creating a custom serializer. 2. Issues: - Performance Overhead: Prefect’s liberal use of Pydantic’s
TypeAdapter
in validating models can have significant overhead. The proposed solution is to create static adapters for reuse. - Deprecation in Pydantic v2: Prefect’s use of
pydantic.v1.SecretStr
leads to errors because of the deprecated
__modify_schema__
method in Pydantic v2. The recommended fix involves updating and replacing deprecated methods. So, there you have it. Links have been provided so you can dive into the riveting details if you desire: - Prefect 3.x Documentation on Inputs and Pydantic - GitHub Issues on Performance: Using Static TypeAdapters - GitHub Issue on Deprecation: `pydantic.v1.SecretStr` - GitHub Issue on JSON Serialization for Pydantic Models Now, off you go to tackle the wonderful, exciting world of data validation and serialization!