prefect.utilities.pydantic
add_cloudpickle_reduction
__reducer__
to the given class that ensures it is cloudpickle compatible.
Workaround for issues with cloudpickle when using cythonized pydantic which
throws exceptions when attempting to pickle the class which has “compiled”
validator methods dynamically attached to it.
We cannot define this utility in the model class itself because the class is the
type that contains unserializable methods.
Any model using some features of Pydantic (e.g. Path
validation) with a Cython
compiled Pydantic installation may encounter pickling issues.
See related issue at https://github.com/cloudpipe/cloudpickle/issues/408
get_class_fields_only
add_type_dispatch
__dispatch_key__
. The base class should
define a __dispatch_key__
class method that is used to determine the unique key
for each subclass. Alternatively, each subclass can define the __dispatch_key__
as a string literal.
The base class must not define a ‘type’ field. If it is not desirable to add a field
to the model and the dispatch key can be tracked separately, the lower level
utilities in prefect.utilities.dispatch
should be used directly.
custom_pydantic_encoder
parse_obj_as
TypeAdapter
.
Read more about TypeAdapter
here.
Args:
type_
: The type to parse the data as.data
: The data to be parsed.mode
: The mode to use for parsing, either python
, json
, or strings
.
Defaults to python
, where data
should be a Python object (e.g. dict
).data
as the given type_
.handle_secret_render
PartialModel
ValueError
will be raised on assignment if
a field already has a value.
Methods:
finalize
raise_if_already_set
raise_if_not_in_model