Commit f5156194 authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

Added an API to control database-level autocommit.

parent 7aacde84
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ class BaseDatabaseWrapper(object):
        self.savepoint_state = 0

        # Transaction management related attributes
        self.autocommit = False
        self.transaction_state = []
        # Tracks if the connection is believed to be in transaction. This is
        # set somewhat aggressively, as the DBAPI doesn't make it easy to
@@ -232,6 +233,12 @@ class BaseDatabaseWrapper(object):
        """
        pass

    def _set_autocommit(self, autocommit):
        """
        Backend-specific implementation to enable or disable autocommit.
        """
        raise NotImplementedError

    ##### Generic transaction management methods #####

    def enter_transaction_management(self, managed=True, forced=False):
@@ -274,6 +281,13 @@ class BaseDatabaseWrapper(object):
            raise TransactionManagementError(
                "Transaction managed block ended with pending COMMIT/ROLLBACK")

    def set_autocommit(self, autocommit=True):
        """
        Enable or disable autocommit.
        """
        self._set_autocommit(autocommit)
        self.autocommit = autocommit

    def abort(self):
        """
        Roll back any ongoing transaction and clean the transaction state
+5 −1
Original line number Diff line number Diff line
import hashlib
import sys
import time
import warnings

from django.conf import settings
from django.db.utils import load_backend
@@ -466,7 +467,10 @@ class BaseDatabaseCreation(object):
        anymore by Django code. Kept for compatibility with user code that
        might use it.
        """
        pass
        warnings.warn(
            "set_autocommit was moved from BaseDatabaseCreation to "
            "BaseDatabaseWrapper.", PendingDeprecationWarning, stacklevel=2)
        return self.connection.set_autocommit()

    def _prepare_for_test_db_ddl(self):
        """
+1 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
    _savepoint_rollback = ignore
    _enter_transaction_management = complain
    _leave_transaction_management = ignore
    _set_autocommit = complain
    set_dirty = complain
    set_clean = complain
    commit_unless_managed = complain
+3 −0
Original line number Diff line number Diff line
@@ -445,6 +445,9 @@ class DatabaseWrapper(BaseDatabaseWrapper):
        except Database.NotSupportedError:
            pass

    def _set_autocommit(self, autocommit):
        self.connection.autocommit(autocommit)

    def disable_constraint_checking(self):
        """
        Disables foreign key checks, primarily for use in adding rows with forward references. Always returns True,
+3 −0
Original line number Diff line number Diff line
@@ -612,6 +612,9 @@ class DatabaseWrapper(BaseDatabaseWrapper):
    def _savepoint_commit(self, sid):
        pass

    def _set_autocommit(self, autocommit):
        self.connection.autocommit = autocommit

    def check_constraints(self, table_names=None):
        """
        To check constraints, we set constraints to immediate. Then, when, we're done we must ensure they
Loading