Skip to content

Commit

Permalink
Return None for SyncCheckpoint.read() when src is empty
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Dye <[email protected]>
  • Loading branch information
andrewwdye committed Sep 24, 2022
1 parent 245c414 commit 941dd74
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion flytekit/core/checkpointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def read(self) -> typing.Optional[bytes]:
if p is None:
return None
files = list(p.iterdir())
if len(files) == 0 or len(files) > 1:
if len(files) == 0:
return None
if len(files) > 1:
raise ValueError(f"Expected exactly one checkpoint - found {len(files)}")
f = files[0]
return f.read_bytes()
Expand Down
10 changes: 10 additions & 0 deletions tests/flytekit/unit/core/test_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ def test_sync_checkpoint_restore_default_path(tmpdir):
assert cp.restore() == cp._prev_download_path


def test_sync_checkpoint_read_empty_dir(tmpdir):
td_path = Path(tmpdir)
dest = td_path.joinpath("dest")
dest.mkdir()
src = td_path.joinpath("src")
src.mkdir()
cp = SyncCheckpoint(checkpoint_dest=str(dest), checkpoint_src=str(src))
assert cp.read() is None


def test_sync_checkpoint_read_multiple_files(tmpdir):
"""
Read can only work with one file.
Expand Down

0 comments on commit 941dd74

Please sign in to comment.