-
-
Notifications
You must be signed in to change notification settings - Fork 125
Description
ensure_autocommit_off() is somewhat confusing:
The docstring states:
Ensure autocommit is off for this database connection.
However, the codes sets self.conn.isolation_level = None, which is documented in the Python stdlib as:
If isolation_level is set to None, no transactions are implicitly opened at all. This leaves the underlying SQLite library in autocommit mode,
https://docs.python.org/3/library/sqlite3.html#sqlite3-transaction-control-isolation-level
So that means that ensure_autocommit_off() actually turns on the sqlite3 in autocommit mode.
AFAIU, in order for ensure_autocommit_off() to actually disable autocommit, it would also need to issue a BEGIN command before yield, so that an explicit transaction is started:
If isolation_level is set to None, no transactions are implicitly opened at all. This leaves the underlying SQLite library in autocommit mode, but also allows the user to perform their own transaction handling using explicit SQL statements.
https://docs.python.org/3/library/sqlite3.html#sqlite3-transaction-control-isolation-level
The last part but also allows the user to perform their own transaction handling using explicit SQL statements. is what an explicit BEGIN would allow.