Review Fix: Improve src/infrastructure/chat_store.py

This commit is contained in:
2026-03-19 21:56:00 -04:00
parent d8d792a6e9
commit d60eff31fe

View File

@@ -60,7 +60,12 @@ class MessageLog:
self._conn: sqlite3.Connection | None = None
# Lazy connection — opened on first use, not at import time.
def _ensure_conn(self) -> sqlite3.Connection:
@contextmanager
def _get_conn(self) -> Generator[sqlite3.Connection, None, None]:
path = self._db_path or DB_PATH
with closing(sqlite3.connect(str(path), check_same_thread=False)) as conn:
conn.row_factory = sqlite3.Row
yield conn
if self._conn is None:
# Open a persistent connection for the class instance
path = self._db_path or DB_PATH