Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
pimdh opened this issue Nov 13, 2024 · 1 comment · May be fixed by flyteorg/flytekit#2926
Open
2 tasks done

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

pimdh opened this issue Nov 13, 2024 · 1 comment · May be fixed by flyteorg/flytekit#2926
Assignees
Labels
bug Something isn't working

Comments

@pimdh
Copy link

pimdh commented Nov 13, 2024

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?

  • Yes

Have you read the Code of Conduct?

  • Yes
@pimdh pimdh added bug Something isn't working untriaged This issues has not yet been looked at by the Maintainers labels Nov 13, 2024
Copy link

welcome bot commented Nov 13, 2024

Thank you for opening your first issue here! 🛠

pimdh added a commit to pimdh/flytekit that referenced this issue Nov 13, 2024
@pimdh pimdh linked a pull request Nov 13, 2024 that will close this issue
3 tasks
pimdh added a commit to pimdh/flytekit that referenced this issue Nov 13, 2024
@eapolinario eapolinario removed the untriaged This issues has not yet been looked at by the Maintainers label Nov 14, 2024
@eapolinario eapolinario self-assigned this Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

2 participants