Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed _enter/_leave_transaction_management.

The goal is to make all databases share a common, autocommit-based,
implementation.
  • Loading branch information...
commit cfc114e00ebe2ac16c37af2ccee1ed8e47247b7a 1 parent 1617557
Aymeric Augustin aaugustin authored
38 django/db/backends/__init__.py
View
@@ -231,21 +231,6 @@ def clean_savepoints(self):
##### Backend-specific transaction management methods #####
- def _enter_transaction_management(self, managed):
- """
- A hook for backend-specific changes required when entering manual
- transaction handling.
- """
- pass
-
- def _leave_transaction_management(self, managed):
- """
- A hook for backend-specific changes required when leaving manual
- transaction handling. Will usually be implemented only when
- _enter_transaction_management() is also required.
- """
- pass
-
def _set_autocommit(self, autocommit):
"""
Backend-specific implementation to enable or disable autocommit.
@@ -268,7 +253,10 @@ def enter_transaction_management(self, managed=True, forced=False):
commit/rollback, the data will be commited, unless "forced" is True.
"""
self.transaction_state.append(managed)
- self._enter_transaction_management(managed)
+
+ if managed and self.autocommit:
+ self.set_autocommit(False)
+
if not managed and self.is_dirty() and not forced:
self.commit()
@@ -283,17 +271,21 @@ def leave_transaction_management(self):
else:
raise TransactionManagementError(
"This code isn't under transaction management")
- # The _leave_transaction_management hook can change the dirty flag,
- # so memoize it.
- dirty = self._dirty
- # We will pass the next status (after leaving the previous state
- # behind) to subclass hook.
- self._leave_transaction_management(self.is_managed())
- if dirty:
+
+ # That's the next state -- we already left the previous state behind.
+ managed = self.is_managed()
+
+ if self._dirty:
self.rollback()
+ if not managed and not self.autocommit:
+ self.set_autocommit(True)
raise TransactionManagementError(
"Transaction managed block ended with pending COMMIT/ROLLBACK")
+ if not managed and not self.autocommit:
+ self.set_autocommit(True)
+
+
def set_autocommit(self, autocommit=True):
"""
Enable or disable autocommit.
2  django/db/backends/dummy/base.py
View
@@ -55,8 +55,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
_savepoint = ignore
_savepoint_commit = complain
_savepoint_rollback = ignore
- _enter_transaction_management = complain
- _leave_transaction_management = ignore
_set_autocommit = complain
set_dirty = complain
set_clean = complain
17 django/db/backends/postgresql_psycopg2/base.py
View
@@ -164,23 +164,6 @@ def close(self):
finally:
self.set_clean()
- def _enter_transaction_management(self, managed):
- """
- Switch the isolation level when needing transaction support, so that
- the same transaction is visible across all the queries.
- """
- if managed and self.autocommit:
- self.set_autocommit(False)
-
- def _leave_transaction_management(self, managed):
- """
- If the normal operating mode is "autocommit", switch back to that when
- leaving transaction management.
- """
- if not managed and not self.autocommit:
- self.rollback() # Must terminate transaction first.
- self.set_autocommit(True)
-
def _set_isolation_level(self, isolation_level):
assert isolation_level in range(1, 5) # Use set_autocommit for level = 0
if self.psycopg2_version >= (2, 4, 2):
Please sign in to comment.
Something went wrong with that request. Please try again.