Skip to content

Commit

Permalink
ObjectDB._init: Ensure self.fs.ls return is not None before iterating.
Browse files Browse the repository at this point in the history
  • Loading branch information
daavoo committed Jun 14, 2023
1 parent 7e07ccf commit f2897f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/dvc_objects/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ def _init(self, dname: str) -> None:
if self._dirs is None:
self._dirs = set()
with suppress(FileNotFoundError, NotImplementedError):
self._dirs = {
self.fs.path.name(path)
for path in self.fs.ls(self.path, detail=False)
}
paths = self.fs.ls(self.path, detail=False)
if paths:
self._dirs = {self.fs.path.name(path) for path in paths}

if dname in self._dirs:
return
Expand Down
10 changes: 10 additions & 0 deletions tests/test_odb.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ def test_odb_add(memfs):
assert memfs.cat_file("/odb/12/34") == b"foo"


def test_odb_add_when_ls_returns_none(memfs, mocker):
"""https://github.com/iterative/dvc/issues/9607"""
memfs.pipe({"foo": b"foo", "bar": b"bar"})
mocker.patch.object(memfs, "ls", return_value=None)

odb = ObjectDB(memfs, "/odb")
odb.add("/foo", memfs, "1234")
assert odb.exists("1234")


def test_delete(memfs):
memfs.pipe({"foo": b"foo", "bar": b"bar"})

Expand Down

0 comments on commit f2897f6

Please sign in to comment.