Compare commits

...
Author SHA1 Message Date
praisonai-triage-agent[bot]andMervin Praison 6f34efd58a fix(session): forward overwrite kwarg in SqliteSessionStore import override
The base DefaultSessionStore._save_imported_session gained an `overwrite`
keyword (passed by import_sessions), but the SqliteSessionStore override and
the test's delayed_save monkeypatch still used the old 2-arg signature,
raising a TypeError that made imports report imported=0. Forward the kwarg so
the override matches the base contract.

Co-authored-by: Mervin Praison <[email protected]>
2026-10-02 13:15:30 +00:00
Wu Shuwen c59d45c950 Return SQLiteBackend clear count from DELETE rowcount 2026-10-02 12:54:19 +01:00
4 changed files with 54 additions and 7 deletions

No files matched your search

@@ -370,9 +370,9 @@ class SqliteSessionStore(DefaultSessionStore):
self._index_session(session)
return ok
def _save_imported_session(self, session: SessionData) -> bool:
def _save_imported_session(self, session: SessionData, *, overwrite: bool = True) -> bool:
"""Refresh recall and routing after a verbatim portable restore."""
ok = super()._save_imported_session(session)
ok = super()._save_imported_session(session, overwrite=overwrite)
if ok:
try:
filepath = self._get_session_path(session.session_id)
@@ -337,10 +337,8 @@ class SQLiteBackend:
conn = self._get_conn()
cur = conn.cursor()
cur.execute(f"SELECT COUNT(*) as count FROM {self._quoted_table}")
count = cur.fetchone()["count"]
cur.execute(f"DELETE FROM {self._quoted_table}")
count = cur.rowcount
conn.commit()
return count
@@ -111,8 +111,8 @@ def test_write_between_import_save_and_index_keeps_newer_content(make_store, mon
resume = threading.Event()
original = DefaultSessionStore._save_imported_session
def delayed_save(store, session):
result = original(store, session)
def delayed_save(store, session, *, overwrite=True):
result = original(store, session, overwrite=overwrite)
saved.set()
assert resume.wait(5), "concurrent writer did not finish"
return result
@@ -0,0 +1,49 @@
"""clear reports the rows its DELETE removes, including committed peer changes."""
import pytest
from praisonaiagents.storage.backends import SQLiteBackend
@pytest.mark.parametrize("change", ["insert", "delete", "none", "empty"])
def test_clear_counts_its_delete_with_a_second_connection(tmp_path, monkeypatch, change):
path = str(tmp_path / "store.db")
backend = SQLiteBackend(db_path=path)
peer = SQLiteBackend(db_path=path)
deleted_keys = []
try:
if change != "empty":
backend.save("first", {"value": 1})
backend.save("second", {"value": 2})
conn = backend._get_conn()
class Cursor:
def __init__(self):
self.cursor = conn.cursor()
def execute(self, sql, *args):
if sql.startswith("DELETE FROM"):
if change == "insert":
peer.save("late", {"value": 3})
elif change == "delete":
assert peer.delete("first")
deleted_keys.extend(peer.list_keys())
return self.cursor.execute(sql, *args)
def __getattr__(self, name):
return getattr(self.cursor, name)
class Connection:
def cursor(self):
return Cursor()
def commit(self):
conn.commit()
monkeypatch.setattr(backend, "_get_conn", lambda: Connection())
assert backend.clear() == len(deleted_keys)
assert len(deleted_keys) == {"insert": 3, "delete": 1, "none": 2, "empty": 0}[change]
assert peer.list_keys() == []
finally:
backend.close()
peer.close()