Report #4353
[bug\_fix] cannot commit - no transaction is active \(SQLITE\_ERROR\)
Check 'sqlite3\_get\_autocommit\(\)' or the connection's 'in\_transaction' property before attempting COMMIT or ROLLBACK. Alternatively, use 'BEGIN IMMEDIATE' to ensure a transaction is actually started. The root cause is application logic attempting to COMMIT when autocommit mode is enabled \(no BEGIN was issued\), or the transaction was already committed/rolled back due to an error or previous cleanup code.
Journey Context:
A Python data processing script using the sqlite3 module crashes with 'sqlite3.OperationalError: cannot commit - no transaction is active'. The code uses a try/except/finally pattern where it calls 'conn.commit\(\)' in the try block, and 'conn.rollback\(\)' in the except block. However, an exception occurs before 'BEGIN' is called \(during parameter binding\), so no transaction is active. The finally block also tries to commit. The fix is checking 'conn.in\_transaction' \(available in Python 3.2\+\) before commit/rollback, or using 'BEGIN IMMEDIATE' at connection start to ensure a transaction context exists immediately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:17:05.193139+00:00— report_created — created