Skip to content

Commit

Permalink
sqlite: don't forget to reset _ids on close
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Dec 22, 2023
1 parent d03f3ce commit 5205b8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/sqltrie/sqlite/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def open(cls, path):
return trie

def close(self):
self._ids = {}

conn = getattr(self._local, "conn", None)
if conn is None:
return
Expand Down
11 changes: 11 additions & 0 deletions tests/test_sqltrie.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ def test_open(tmp_path):
trie[("foo", "bar", "baz")] = b"baz-value"

trie.commit()

assert trie._ids == {(): 1, ("foo",): 2, ("foo", "bar"): 3}
assert trie._local.conn
trie.close()
assert not trie._ids
assert not hasattr(trie._local, "conn")

trie = SQLiteTrie.open(path)

Expand All @@ -146,6 +151,12 @@ def test_open(tmp_path):
assert trie[("foo",)] == b"foo-value"
assert trie[("foo", "bar", "baz")] == b"baz-value"

assert not trie._ids
assert trie._local.conn
trie.close()
assert not trie._ids
assert not hasattr(trie._local, "conn")


@pytest.mark.parametrize("cls", [SQLiteTrie, PyGTrie])
def test_view(cls):
Expand Down

0 comments on commit 5205b8f

Please sign in to comment.