Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored March 03, 2013
38  django/db/backends/__init__.py
@@ -231,21 +231,6 @@ def clean_savepoints(self):
231 231
 
232 232
     ##### Backend-specific transaction management methods #####
233 233
 
234  
-    def _enter_transaction_management(self, managed):
235  
-        """
236  
-        A hook for backend-specific changes required when entering manual
237  
-        transaction handling.
238  
-        """
239  
-        pass
240  
-
241  
-    def _leave_transaction_management(self, managed):
242  
-        """
243  
-        A hook for backend-specific changes required when leaving manual
244  
-        transaction handling. Will usually be implemented only when
245  
-        _enter_transaction_management() is also required.
246  
-        """
247  
-        pass
248  
-
249 234
     def _set_autocommit(self, autocommit):
250 235
         """
251 236
         Backend-specific implementation to enable or disable autocommit.
@@ -268,7 +253,10 @@ def enter_transaction_management(self, managed=True, forced=False):
268 253
         commit/rollback, the data will be commited, unless "forced" is True.
269 254
         """
270 255
         self.transaction_state.append(managed)
271  
-        self._enter_transaction_management(managed)
  256
+
  257
+        if managed and self.autocommit:
  258
+            self.set_autocommit(False)
  259
+
272 260
         if not managed and self.is_dirty() and not forced:
273 261
             self.commit()
274 262
 
@@ -283,17 +271,21 @@ def leave_transaction_management(self):
283 271
         else:
284 272
             raise TransactionManagementError(
285 273
                 "This code isn't under transaction management")
286  
-        # The _leave_transaction_management hook can change the dirty flag,
287  
-        # so memoize it.
288  
-        dirty = self._dirty
289  
-        # We will pass the next status (after leaving the previous state
290  
-        # behind) to subclass hook.
291  
-        self._leave_transaction_management(self.is_managed())
292  
-        if dirty:
  274
+
  275
+        # That's the next state -- we already left the previous state behind.
  276
+        managed = self.is_managed()
  277
+
  278
+        if self._dirty:
293 279
             self.rollback()
  280
+            if not managed and not self.autocommit:
  281
+                self.set_autocommit(True)
294 282
             raise TransactionManagementError(
295 283
                 "Transaction managed block ended with pending COMMIT/ROLLBACK")
296 284
 
  285
+        if not managed and not self.autocommit:
  286
+            self.set_autocommit(True)
  287
+
  288
+
297 289
     def set_autocommit(self, autocommit=True):
298 290
         """
299 291
         Enable or disable autocommit.
2  django/db/backends/dummy/base.py
@@ -55,8 +55,6 @@ class DatabaseWrapper(BaseDatabaseWrapper):
55 55
     _savepoint = ignore
56 56
     _savepoint_commit = complain
57 57
     _savepoint_rollback = ignore
58  
-    _enter_transaction_management = complain
59  
-    _leave_transaction_management = ignore
60 58
     _set_autocommit = complain
61 59
     set_dirty = complain
62 60
     set_clean = complain
17  django/db/backends/postgresql_psycopg2/base.py
@@ -164,23 +164,6 @@ def close(self):
164 164
         finally:
165 165
             self.set_clean()
166 166
 
167  
-    def _enter_transaction_management(self, managed):
168  
-        """
169  
-        Switch the isolation level when needing transaction support, so that
170  
-        the same transaction is visible across all the queries.
171  
-        """
172  
-        if managed and self.autocommit:
173  
-            self.set_autocommit(False)
174  
-
175  
-    def _leave_transaction_management(self, managed):
176  
-        """
177  
-        If the normal operating mode is "autocommit", switch back to that when
178  
-        leaving transaction management.
179  
-        """
180  
-        if not managed and not self.autocommit:
181  
-            self.rollback()                     # Must terminate transaction first.
182  
-            self.set_autocommit(True)
183  
-
184 167
     def _set_isolation_level(self, isolation_level):
185 168
         assert isolation_level in range(1, 5)     # Use set_autocommit for level = 0
186 169
         if self.psycopg2_version >= (2, 4, 2):

0 notes on commit cfc114e

Please sign in to comment.
Something went wrong with that request. Please try again.