<#6560 [BUG] [flytekit] FlyteFile/Directory to_dic...
# flyte-github
a
#6560 [BUG] [flytekit] FlyteFile/Directory to_dict behavior changes Issue created by wild-endeavor Flyte & Flytekit version Latest flytekit Describe the bug Basically if I have a FlyteFile object, the
to_dict
is a little different depending on whether or not it's in a dataclass. Basically these show different things.
Copy code
ff = FlyteFile("<gs://foo/bar.txt>")
ff_dict = ff.to_dict()
print(ff_dict)

@dataclass
class Car(DataClassJSONMixin):
    wheels: list[FlyteFile]

c = Car(wheels=[FlyteFile("<gs://foo/bar.txt>")])
cc_dict = c.to_dict()
print(cc_dict)
The first case actually just returns an empty dict
{}
. Some GPT-powered digging reveals that the root cause of this behavior is a combination of •
FlyteFile
having its own
__init__
function •
FlyteFile
inheriting from both
SerializableType
and
DataClassJSONMixin
The example above has been partially copied into this branch. Adding the
to_dict
override does indeed work for serializing but didn't add from_dict yet. Didn't look into what the correct signature is. Expected behavior Ideally common functions like
to/from_dict
and
to/from_json
should behave correctly (not have surprising behavior) and should be consistent whether used in a dataclass or used by itself. We should fix flytekit if possible but it's also more important that we get this right in the v2 sdk. Note that in v2, File/Dir are now Pydantic models so this may just be fixed (but we should add tests there to ensure they work). Any fix needs to not break any other users of course. If for some reason it's undesirable to have these
to/from_dict/json
functions, we should document and maybe go as far as to implement them as raise Exception and explain why. (for both v1 and v2). Are you sure this issue hasn't been raised already? • Yes Have you read the Code of Conduct? • Yes flyteorg/flyte