flyteorg / flyte

Scalable and flexible workflow orchestration platform that seamlessly unifies data, ML and analytics stacks.
https://flyte.org
Apache License 2.0
5.79k stars 659 forks source link

[BUG] FlyteDirectory.listdir does not return full paths for local files #6005

Open pimdh opened 5 days ago

pimdh commented 5 days ago

Describe the bug

Thanks for this great library!

For local files, FlyteDirectory.listdir returns only the names of the files/dirs in the given directory, not the full paths. This breaks the following workflow.

import tempfile
from pathlib import Path

from flytekit import FlyteDirectory, FlyteFile, map_task, task, workflow

@task
def setup() -> FlyteDirectory:
    tmpdir = Path(tempfile.mkdtemp())
    for i in range(3):
        (tmpdir / f"file{i}.txt").write_text(f"Hello, World! {i}")
    return FlyteDirectory(tmpdir)

@task
def read_file(file: FlyteFile) -> str:
    with open(file, "r") as f:
        return f.read()

@task
def list_dir(dir: FlyteDirectory) -> list[FlyteFile]:
    return FlyteDirectory.listdir(dir)

@workflow
def wf() -> list[str]:
    tmpdir = setup()
    files = list_dir(dir=tmpdir)
    return map_task(read_file)(file=files)

Run with pyflyte run debug_flyte.py wf.

This issue arises because only the file/dir name is returned, not the joined path here.

Expected behavior

I would expect to get the outputs:

['Hello, World! 0', 'Hello, World! 2', 'Hello, World! 1']

(in some order), but instead I get

Running Execution on local.
FlyteAssertion: USER:AssertionError: error=Error encountered while converting inputs of 'debug_flyte.map_read_file_6b3bd0353da5de6e84d7982921ead2b3-arraynode':
  Cannot convert from Flyte Serialized object (Literal):
  scalar:
    blob:
      metadata:
      uri: file0.txt to <class 'flytekit.types.file.file.FlyteFile'>. Expected a file, but file0.txt is not a file.

Additional context to reproduce

No response

Screenshots

No response

Are you sure this issue hasn't been raised already?

Have you read the Code of Conduct?

welcome[bot] commented 5 days ago

Thank you for opening your first issue here! 🛠