Maybe the example of custom TypeTransformer could help:
def to_literal(
self,
ctx: FlyteContext,
python_val: PickleDataClassMixin,
python_type: Type[PickleDataClassMixin],
expected: LiteralType,
) -> Literal:
path = persist_python_value(python_val)
json_repr = maybe_get_json_repr(python_val)
blob_literal = Literal(
scalar=Scalar(blob=Blob(uri=path, metadata=BlobMetadata(type=self._TYPE_INFO)))
)
if json_repr is None:
literal = Literal(map=LiteralMap(literals={"pickle_path": blob_literal}))
else:
structure_literal = Literal(
scalar=Scalar(generic=_json_format.Parse(json_repr, _struct.Struct())),
)
literal = Literal(
map=LiteralMap(
literals={"pickle_path": blob_literal, "structure": structure_literal}
)
)
return literal
In this example:
• the transformer returns
dict(pickle_path=blob_literal, structure=structure_literal)
if the object is json serializable, else returns
dict(pickle_path=blob_literal)
• The
to_python_value
method only uses the
pickle_path
to convert back into python object
This works quite well - objects with a json repr show up with both
pickle_path
and
structure
attribute in flyte console (see screenshot 1)
What I’d like to do is to switch between
pickle_path + structure
and only
pickle_path
based on if the literal is being created to be passed into a
task
vs
dynamic
(hope that makes it more clear, I am not trying to mutate types, just their representations in the UI)