From d60eff31fee955161d42c799e4d6ab10066d88ad Mon Sep 17 00:00:00 2001 From: Google AI Studio Date: Thu, 19 Mar 2026 21:56:00 -0400 Subject: [PATCH] Review Fix: Improve src/infrastructure/chat_store.py --- src/infrastructure/chat_store.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/infrastructure/chat_store.py b/src/infrastructure/chat_store.py index 72037e5..41d63ad 100644 --- a/src/infrastructure/chat_store.py +++ b/src/infrastructure/chat_store.py @@ -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