diff --git a/flytekit/types/file/file.py b/flytekit/types/file/file.py index 15113f8f01..567b29de57 100644 --- a/flytekit/types/file/file.py +++ b/flytekit/types/file/file.py @@ -440,6 +440,9 @@ def to_literal( # Set the remote destination if one was given instead of triggering a random one below remote_path = python_val.remote_path or None + if ctx.execution_state.is_local_execution and python_val.remote_path is None: + should_upload = False + elif isinstance(python_val, pathlib.Path) or isinstance(python_val, str): source_path = str(python_val) if issubclass(python_type, FlyteFile): @@ -455,6 +458,8 @@ def to_literal( p = pathlib.Path(python_val) if not p.is_file(): raise TypeTransformerFailedError(f"Error converting {python_val} because it's not a file.") + if ctx.execution_state.is_local_execution: + should_upload = False # python_type must be os.PathLike - see check at beginning of function else: should_upload = False diff --git a/tests/flytekit/unit/core/test_flyte_file.py b/tests/flytekit/unit/core/test_flyte_file.py index ff038c164b..b1331adea7 100644 --- a/tests/flytekit/unit/core/test_flyte_file.py +++ b/tests/flytekit/unit/core/test_flyte_file.py @@ -205,7 +205,7 @@ def my_wf(fname: os.PathLike = SAMPLE_DATA) -> int: assert sample_lp.parameters.parameters["fname"].default.scalar.blob.uri == SAMPLE_DATA -def test_file_handling_local_file_gets_copied(): +def test_file_handling_local_file_does_not_get_copied(): @task def t1() -> FlyteFile: # Use this test file itself, since we know it exists. @@ -223,12 +223,7 @@ def my_wf() -> FlyteFile: assert len(top_level_files) == 1 # the flytekit_local folder x = my_wf() - - # After running, this test file should've been copied to the mock remote location. - mock_remote_files = os.listdir(os.path.join(random_dir, "mock_remote")) - assert len(mock_remote_files) == 1 # the file - # File should've been copied to the mock remote folder - assert x.path.startswith(random_dir) + assert x.path == __file__ def test_file_handling_local_file_gets_force_no_copy():