'Enable or disable autocommit.
The usual way to start a transaction is to turn autocommit off.
SQLite does not properly start a transaction when disabling
autocommit. To avoid this buggy behavior and to actually enter a new
transaction, an explcit BEGIN is required. Using
force_begin_transaction_with_broken_autocommit=True will issue an
explicit BEGIN with SQLite. This option will be ignored for other
backends.'

def set_autocommit(self, autocommit, force_begin_transaction_with_broken_autocommit=False):

    self.validate_no_atomic_block()
    self.ensure_connection()
    start_transaction_under_autocommit = (force_begin_transaction_with_broken_autocommit and (not autocommit) and self.features.autocommits_when_autocommit_is_off)
    if start_transaction_under_autocommit:
        self._start_transaction_under_autocommit()
    else:
        self._set_autocommit(autocommit)
    self.autocommit = autocommit
    if (autocommit and self.run_commit_hooks_on_set_autocommit_on):
        self.run_and_clear_commit_hooks()
        self.run_commit_hooks_on_set_autocommit_on = False
