Hey all, We pass around python dataclass-based ob...
# flytekit
t
Hey all, We pass around python dataclass-based objects for our flyte task inputs and outputs, but I've noticed if I try to use a
typing.Union
type for a field, e.g.
my_param: Union[int,list[int]]=field(default_factory=list)
, Flyte complains like so:
Copy code
# "Failed to extract schema for object <class 'plaster.run.sim_v3.sim_v3_params.SimV3Params'>, (will run schemaless) error: unsupported field type <fields._UnionField(dump_default=<class 'list'>, attribute=None, validate=None, required=False, load_only=False, dump_only=False, load_default=<marshmallow.missing>, allow_none=False, error_messages={'required': 'Missing data for required field.', 'null': 'Field may not be null.', 'validator_failed': 'Invalid value.'})>If you have postponed annotations turned on (PEP 563) turn it off please. Postponedevaluation doesn't work with json dataclasses"
I am not using postponed annotations in this case. The reason for my use of Union is trying to migrate the schema of a dataclass member from int to list[int]. I need to support loading older jobs, so thought the Union was an expedient solution, allowing me to init the dataclass with either an int (older jobs) or a list[int] (new jobs). I am on python 3.9 - I mention this because I seem to recall reading something related (maybe this issue?) that goes away beyond 3.9, but maybe I'm thinking of the "futures" issue related to postponed evaluations. Thanks! Thomas
k
you can’t use union type in dataclass for now. we are working on new dataclass transformer that allows you to serialize union
t
OK, thanks!
126 Views