<#3187 [BUG] Handle Optional FlyteFile in dataclasses> Issue created by <eapolinario> Describe the b...
a
#3187 [BUG] Handle Optional FlyteFile in dataclasses Issue created by eapolinario Describe the bug The dataclass type transformer does not handle fields of type
Optional[FlyteFile]
correctly. For example, this workflow fails:
Copy code
from dataclasses import dataclass
from typing import Optional

from dataclasses_json import dataclass_json
from flytekit import workflow, task
from flytekit.types.file import FlyteFile


@dataclass_json
@dataclass
class TaskOutput:
    file1: FlyteFile
    file2: Optional[FlyteFile]

@task
def task1() -> TaskOutput:
    with open("file21.txt", "w+") as f:
        f.write("b")
    with open("file22.txt", "w+") as f:
        f.write("c")

    return TaskOutput(
        FlyteFile("file21.txt", remote_path="<s3://my-s3-bucket/tmp/file21.txt>"),
        FlyteFile("file22.txt", remote_path="<s3://my-s3-bucket/tmp/file22.txt>")
    )

@task
def assert_values_in_dataclass(to: TaskOutput):
    assert to.file1.remote_source == "<s3://my-s3-bucket/tmp/file21.txt>"
    assert to.file2.remote_source == "<s3://my-s3-bucket/tmp/file22.txt>"


@workflow
def wf():
    to = task1()
    assert_values_in_dataclass(to=to)
Expected behavior
Optional[FlyteFile]
should be allowed in Dataclasses. Additional context to reproduce No response Screenshots No response Are you sure this issue hasn't been raised already? ☑︎ Yes Have you read the Code of Conduct? ☑︎ Yes flyteorg/flyte