1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26: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

@@ -42,8 +42,17 @@ backend = load_backend(connection.settings_dict['ENGINE'])
# Register an event that closes the database connection
# when a Django request is finished.
def close_connection(**kwargs):
for conn in connections.all():
conn.close()
# Avoid circular imports
from django.db import transaction
for conn in connections:
try:
transaction.abort(conn)
connections[conn].close()
except Exception:
# The connection's state is unknown, so it has to be
# abandoned. This could happen for example if the network
# connection has a failure.
del connections[conn]
signals.request_finished.connect(close_connection)
# Register an event that resets connection.queries