Skip to content

Commit

Permalink
fix: include remote file paths with special characters (flyteorg#2478)
Browse files Browse the repository at this point in the history
Signed-off-by: Rishi Ravikumar <[email protected]>
Signed-off-by: bugra.gedik <[email protected]>
  • Loading branch information
RRK1000 authored and bugra.gedik committed Jul 3, 2024
1 parent aeed8ff commit e6c083f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion flytekit/types/file/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import typing
from contextlib import contextmanager
from dataclasses import dataclass, field
from urllib.parse import unquote

from dataclasses_json import config
from marshmallow import fields
Expand Down Expand Up @@ -468,7 +469,7 @@ def to_literal(
remote_path = ctx.file_access.put_data(source_path, remote_path, is_multipart=False, **headers)
else:
remote_path = ctx.file_access.put_raw_data(source_path, **headers)
return Literal(scalar=Scalar(blob=Blob(metadata=meta, uri=remote_path)))
return Literal(scalar=Scalar(blob=Blob(metadata=meta, uri=unquote(str(remote_path)))))
# If not uploading, then we can only take the original source path as the uri.
else:
return Literal(scalar=Scalar(blob=Blob(metadata=meta, uri=source_path)))
Expand Down
18 changes: 18 additions & 0 deletions tests/flytekit/unit/core/test_flyte_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,24 @@ def wf(path: str) -> os.PathLike:

assert flyte_tmp_dir in wf(path="s3://somewhere").path

def test_flyte_file_name_with_special_chars():
temp_dir = tempfile.TemporaryDirectory()
file_path = os.path.join(temp_dir.name, "foo bar")
try:
with open(file_path, "w") as tmp:
tmp.write("hello world")

@task
def get_file_path(f: FlyteFile) -> FlyteFile:
return f.path

@workflow
def wf(f: FlyteFile) -> FlyteFile:
return get_file_path(f=f)

wf(f=file_path)
finally:
temp_dir.cleanup()

def test_flyte_file_annotated_hashmethod(local_dummy_file):
def calc_hash(ff: FlyteFile) -> str:
Expand Down

0 comments on commit e6c083f

Please sign in to comment.