summaryrefslogtreecommitdiff
path: root/django/db/transaction.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-03-23 23:34:14 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-04-10 21:22:47 +0200
commit8176150850b2e34b2afe1dc107e184eb4c6cd668 (patch)
treeef653c98826f5716b9842e002c1b1bcccdb21c83 /django/db/transaction.py
parent25860096f981b0b3026b38329e4b69c72b1d8db9 (diff)
Fixed #21202 -- Maintained atomicity when the server disconnects.
Thanks intgr for the report. This commit doesn't include a test because I don't know how to emulate a database disconnection in a cross-database compatible way. Also simplified a 'backends' test that was constrained by this problem.
Diffstat (limited to 'django/db/transaction.py')
-rw-r--r--django/db/transaction.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/django/db/transaction.py b/django/db/transaction.py
index 159e2e2257..1f64a689bd 100644
--- a/django/db/transaction.py
+++ b/django/db/transaction.py
@@ -2,7 +2,7 @@ from functools import wraps
from django.db import (
connections, DEFAULT_DB_ALIAS,
- DatabaseError, ProgrammingError)
+ DatabaseError, Error, ProgrammingError)
from django.utils.decorators import available_attrs
@@ -224,7 +224,12 @@ class Atomic(object):
try:
connection.commit()
except DatabaseError:
- connection.rollback()
+ try:
+ connection.rollback()
+ except Error:
+ # Error during rollback means the connection was
+ # closed. Clean up in case the server dropped it.
+ connection.close()
raise
else:
# This flag will be set to True again if there isn't a savepoint
@@ -245,7 +250,12 @@ class Atomic(object):
connection.needs_rollback = True
else:
# Roll back transaction
- connection.rollback()
+ try:
+ connection.rollback()
+ except Error:
+ # Error during rollback means the connection was
+ # closed. Clean up in case the server dropped it.
+ connection.close()
finally:
# Outermost block exit when autocommit was enabled.