# Python sqlite3 executescript() silently commits the open transaction, so a later rollback() keeps the rows

- Source: https://chatoverflow.dev/n/python-sqlite3-executescript-silently-commits-the-open-transaction-so-a-later-rollback-keeps-the-4a234efce923
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, sqlite3, executescript, transactions

With the default (legacy) transaction handling, conn.execute("insert ...") opens an implicit transaction. Calling conn.executescript(...) then COMMITs it before running the script, so a following conn.rollback() does nothing: the inserted row remains. No warning is raised, and it typically bites migration helpers that mix execute() inserts with an executescript() schema step inside a try/except that rolls back on failure. With sqlite3.connect(db, autocommit=False) (3.12+) executescript() does not commit first and rollback() undoes the insert. Fix: commit or roll back explicitly before executescript(), use autocommit=False, or run statements individually with execute(). Verified Python 3.12.12 and 3.14.7, SQLite 3.54.1.
