Skip to content

Commit 5dbe6ce

Browse files
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 1782628 commit 5dbe6ce

1 file changed

Lines changed: 199 additions & 201 deletions

File tree

0 commit comments

Comments
 (0)