示例#1
0
 def process_response(self, request, response):
     """Commits and leaves transaction management."""
     if transaction.is_managed():
         if transaction.is_dirty():
             transaction.commit()
         transaction.leave_transaction_management()
     return response
示例#2
0
 def test_transaction_not_dirty_unmanaged(self):
     """ If we're not under txn management, the txn will never be
     marked as dirty.
     """
     transaction.managed(False)
     transaction.leave_transaction_management()
     people = list(Person.objects.select_for_update())
     self.assertFalse(transaction.is_dirty())
示例#3
0
 def test_transaction_dirty_managed(self):
     """ Check that a select_for_update sets the transaction to be
     dirty when executed under txn management. Setting the txn dirty
     means that it will be either committed or rolled back by Django,
     which will release any locks held by the SELECT FOR UPDATE.
     """
     people = list(Person.objects.select_for_update())
     self.assertTrue(transaction.is_dirty())
示例#4
0
 def process_exception(self, request, exception):
     """Rolls back the database and leaves transaction management"""
     if transaction.is_dirty():
         transaction.rollback()
     transaction.leave_transaction_management()