Skip to content

Commit

Permalink
more comments, slightly different test
Browse files Browse the repository at this point in the history
Signed-off-by: Yee Hing Tong <[email protected]>
  • Loading branch information
wild-endeavor committed Dec 14, 2021
1 parent 97ab89f commit d3594b1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion flytekit/core/type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,12 @@ def _serialize_flyte_type(self, python_val: T, python_type: Type[T]):
lv = TypeEngine.to_literal(FlyteContext.current_context(), v, field_type, None)
# dataclass_json package will extract the "path" from FlyteFile, FlyteDirectory, and write it to a
# JSON which will be stored in IDL. The path here should always be a remote path, but sometimes the
# path in FlyteFile and FlyteDirectory could be a local path. Therefore, We reset the python value here,
# path in FlyteFile and FlyteDirectory could be a local path. Therefore, reset the python value here,
# so that dataclass_json can always get a remote path.
# In other words, the file transformer has special code that handles the fact that if remote_source is
# set, then the real uri in the literal should be the remote source, not the path (which may be an
# auto-generated random local path). To be sure we're writing the right path to the json, use the uri
# as determined by the transformer.
if issubclass(field_type, FlyteFile) or issubclass(field_type, FlyteDirectory):
python_val.__setattr__(f.name, field_type(path=lv.scalar.blob.uri))

Expand Down
25 changes: 25 additions & 0 deletions tests/flytekit/unit/core/test_flyte_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,28 @@ def test_file_guess():
fft = transformer.guess_python_type(lt)
assert issubclass(fft, FlyteFile)
assert fft.extension() == ""


def test_flyte_file_in_dyn():
@task
def t1(path: str) -> FlyteFile:
return FlyteFile(path)

@dynamic
def dyn(fs: FlyteFile):
t2(ff=fs)

@task
def t2(ff: FlyteFile) -> os.PathLike:
assert ff.remote_source == "s3://somewhere"
assert "/tmp/flyte/" in ff.path

return ff.path

@workflow
def wf(path: str) -> os.PathLike:
n1 = t1(path=path)
dyn(fs=n1)
return t2(ff=n1)

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

0 comments on commit d3594b1

Please sign in to comment.