Skip to content

ensure_autocommit_off() is confusing #705

@douglas-raillard-arm

Description

@douglas-raillard-arm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions