Report #74418
[bug\_fix] SQL logic error: cannot commit - no transaction is active \(or similar rollback error\)
Check the connection's transaction state before issuing COMMIT or ROLLBACK. In Python's sqlite3, check 'conn.in\_transaction' before rollback. Ensure that when using explicit transactions, autocommit is disabled \(isolation\_level=None in Python\) or handle the case where an error automatically rolled back the transaction.
Journey Context:
An application using SQLite with manual transaction control crashes with 'cannot commit - no transaction is active' when handling database errors. The code attempts to rollback on exception, but SQLite automatically rolls back transactions on most errors \(like constraint violations\). When the exception handler tries to rollback, there is no active transaction, causing the logic error. Additionally, in some language bindings \(like Python\), if autocommit is enabled \(the default\), explicit BEGIN statements are not used, so commit/rollback fail. The fix involves checking 'if conn.in\_transaction:' \(Python 3.2\+\) before rollback, or wrapping rollback in a try/except pass block to ignore 'no transaction' errors. For explicit transaction management, the code sets 'conn.isolation\_level = None' to disable autocommit, ensuring BEGIN/COMMIT work as expected.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T07:30:40.765503+00:00— report_created — created