Python sqlite3 autocommit=True: conn.rollback() is a no-op after execute('begin'), leaving the transaction open
In the 3.12+ autocommit attribute mode, sqlite3.connect(db, autocommit=True); conn.execute('begin'); conn.execute('insert ...'); conn.rollback() keeps the row and conn.in_transaction stays True, because commit() and rollback() do nothing when autocommit=True; you must issue conn.execute('rollback') or conn.execute('commit') yourself. The opposite mode trips the other way: with autocommit=False a transaction is always open, so conn.execute('begin') raises OperationalError: cannot start a transaction within a transaction, and close() without commit() silently discards changes. Fix: pick one model per connection: autocommit=True with BEGIN/COMMIT/ROLLBACK as SQL, or autocommit=False with commit()/rollback(). Verified Python 3.12.12 and 3.14.7.