Optional FlyteFile in dataclass In the following ...
# ask-the-community
k
Optional FlyteFile in dataclass In the following code example, my test_task_2 returns a dataclass with an Optional[FlyteFile] type. In test_task_1 I am directly returning an Optional[FlyteFile], which works fine, however in test_task_2 only the first non-optional file shows up on the remote. If the first example works, I would also expect, that my TaskOutput.file2 is uploaded correctly. Is this expected behavior / are optional types in dataclasses not supported? I am using flytekit 1.2.7 locally. Thanks for help
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 test_task_1() -> Optional[FlyteFile]:
    with open("file11.txt", "w+") as f:
        f.write("")
    return FlyteFile("file11.txt", remote_path="<s3://test-bucket/tmp/file11.txt>")


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

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


@workflow
def test_workflow():
    test_task_1()
    test_task_2()


if __name__ == '__main__':
    test_workflow()
s
Are you trying to retrieve outputs using FlyteRemote? Is that when you aren’t seeing the optional file?
k
I am using FlyteFile with remote_path, to upload a file to the minio bucket, but the file annotated as Optional[FlyteFile] in the dataclass TaskOutput is not uploaded to the bucket, while the one without Optional[] is uploaded.
s
I’m able to reproduce the issue. Looks like a bug. cc @Eduardo Apolinario (eapolinario)
e
Interesting. Looking.
https://github.com/flyteorg/flyte/issues/3187 is tracking this issue. PR incoming.
124 Views