Commit 40a979a
committed
fix: make knowledge_graph.py SQLite connections exception-safe
Wrap all 8 methods that open SQLite connections with
contextlib.closing() to guarantee conn.close() is called even if
execute()/commit()/fetchall() raises. Previously, connections would
leak on exception since close() was called manually after operations.
Add transaction context manager (with conn:) to write methods
(add_entity, add_triple, invalidate) for auto-commit on success and
auto-rollback on exception. Read methods use closing() only.
_init_db keeps manual commit since executescript has its own
transaction semantics.1 parent 71736a3 commit 40a979a
1 file changed
Lines changed: 200 additions & 202 deletions
0 commit comments