1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #19707 -- Reset transaction state after requests

This commit is contained in:
Anssi Kääriäinen
2013-02-05 23:52:29 +02:00
parent 0e18fb04ba
commit a4e97cf315
8 changed files with 127 additions and 6 deletions

View File

@@ -24,6 +24,21 @@ class TransactionManagementError(Exception):
"""
pass
def abort(using=None):
"""
Roll back any ongoing transactions and clean the transaction management
state of the connection.
This method is to be used only in cases where using balanced
leave_transaction_management() calls isn't possible. For example after a
request has finished, the transaction state isn't known, yet the connection
must be cleaned up for the next request.
"""
if using is None:
using = DEFAULT_DB_ALIAS
connection = connections[using]
connection.abort()
def enter_transaction_management(managed=True, using=None):
"""
Enters transaction management for a running thread. It must be balanced with