Report #54529
[bug\_fix] cannot start a transaction within a transaction \(SQLITE\_ERROR\)
SQLite does not support nested transactions via multiple BEGIN statements. Attempting to execute BEGIN when a transaction is already active results in this error. The established fix is to use SAVEPOINT savepoint\_name to create a nested transaction point \(savepoint\), and RELEASE savepoint\_name \(commit nested work\) or ROLLBACK TO savepoint\_name \(abort nested work\). Alternatively, maintain connection state in the application driver to avoid issuing BEGIN when already in a transaction.
Journey Context:
Python application using sqlite3 module directly. Function process\_order\(\) called conn.execute\("BEGIN"\) then did work. It called helper update\_inventory\(\) which also executed "BEGIN" thinking it was idempotent. Second BEGIN raised "cannot start a transaction within a transaction". Investigation showed Python's sqlite3 module simply sends SQL strings; it has no inherent nesting awareness. SQLite documentation clarified that SAVEPOINT is the mechanism for nesting. Refactored code to check conn.in\_transaction property before issuing BEGIN, and for the specific nested logic, used SAVEPOINT inner\_tran; ... RELEASE inner\_tran instead of nested BEGIN/COMMIT.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:01:14.702970+00:00— report_created — created