Explicitly close status database

Using `__del__` often closes the database on a different thread, which
is not supported by the sqlite module and produces a different warning.

Explicitly close the status database everywhere it is used.
This commit is contained in:
Hugo Osvaldo Barrera 2025-08-25 17:33:20 +02:00
parent 164559ad7a
commit 78f41d32ce
4 changed files with 11 additions and 11 deletions

View file

@ -34,3 +34,5 @@ def test_legacy_status(status_dict):
assert meta2_a.to_status() == meta_a
assert meta2_b.to_status() == meta_b
assert ident_a == ident_b == ident
status.close()

View file

@ -1,6 +1,7 @@
from __future__ import annotations
import asyncio
import contextlib
from copy import deepcopy
import aiostream
@ -25,13 +26,12 @@ from vdirsyncer.sync.status import SqliteStatus
from vdirsyncer.vobject import Item
async def sync(a, b, status, *args, **kwargs):
new_status = SqliteStatus(":memory:")
new_status.load_legacy_status(status)
rv = await _sync(a, b, new_status, *args, **kwargs)
status.clear()
status.update(new_status.to_legacy_status())
return rv
async def sync(a, b, status, *args, **kwargs) -> None:
with contextlib.closing(SqliteStatus(":memory:")) as new_status:
new_status.load_legacy_status(status)
await _sync(a, b, new_status, *args, **kwargs)
status.clear()
status.update(new_status.to_legacy_status())
def empty_storage(x):

View file

@ -232,7 +232,8 @@ def manage_sync_status(base_path: str, pair_name: str, collection_name: str):
prepare_status_path(path)
status = SqliteStatus(path)
yield status
with contextlib.closing(status):
yield status
def save_status(

View file

@ -174,9 +174,6 @@ class SqliteStatus(_StatusBase):
self._c.close()
self._c = None
def __del__(self):
self.close()
def _is_latest_version(self):
try:
return bool(