Commit dc11fbc
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 68e3414 commit dc11fbc
1 file changed
Lines changed: 199 additions & 201 deletions
0 commit comments