Skip to content

Commit

Permalink
index: don't forget to reset _cache on close
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Dec 22, 2023
1 parent 9b3e411 commit 97d8e59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/dvc_data/index/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ def delete_node(self, key):
self._cache.pop(key, None)
super().delete_node(key)

def close(self):
self._cache = {}
super().close()


class Storage(ABC):
def __init__(self, key: "DataIndexKey"):
Expand Down
6 changes: 6 additions & 0 deletions tests/index/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,17 @@ def test_open(tmp_path):
assert index[key] == entry2

index.commit()
assert index._trie._cache
index.close()
assert not index._trie._cache

index = DataIndex.open(path)
index[key] = entry2
assert index[key] == entry2

index[key] = entry1
assert index[key] == entry1

assert index._trie._cache
index.close()
assert not index._trie._cache

0 comments on commit 97d8e59

Please sign in to comment.