summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-03-23 21:45:31 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-04-10 23:22:13 +0200
commit4ea02bdb0dc6776fc29d8164e417469c9ba10f18 (patch)
tree73fb0f576d0a46ec943f2411000cb3f6deb7eeac /tests
parent746cded010c7ba3e2bf2df4cde32dcc9b75cb0d3 (diff)
[1.6.x] Fixed #21239 -- Maintained atomicity when closing the connection.
Refs #15802 -- Reverted #7c657b24 as BaseDatabaseWrapper.close() now has a proper "finally" clause that may need to preserve self.connection. Backport of 25860096 from master.
Diffstat (limited to 'tests')
-rw-r--r--tests/transactions/tests.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py
index 7fc4c0b80b..dbde56f070 100644
--- a/tests/transactions/tests.py
+++ b/tests/transactions/tests.py
@@ -8,7 +8,7 @@ except ImportError:
import time
from django.db import (connection, transaction,
- DatabaseError, IntegrityError, OperationalError)
+ DatabaseError, Error, IntegrityError, OperationalError)
from django.test import TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature
from django.test.utils import IgnorePendingDeprecationWarningsMixin
from django.utils import six
@@ -359,6 +359,20 @@ class AtomicErrorsTests(TransactionTestCase):
r2.save(force_update=True)
self.assertEqual(Reporter.objects.get(pk=r1.pk).last_name, "Calculus")
+ @skipUnlessDBFeature('test_db_allows_multiple_connections')
+ def test_atomic_prevents_queries_in_broken_transaction_after_client_close(self):
+ with transaction.atomic():
+ Reporter.objects.create(first_name="Archibald", last_name="Haddock")
+ connection.close()
+ # The connection is closed and the transaction is marked as
+ # needing rollback. This will raise an InterfaceError on databases
+ # that refuse to create cursors on closed connections (PostgreSQL)
+ # and a TransactionManagementError on other databases.
+ with self.assertRaises(Error):
+ Reporter.objects.create(first_name="Cuthbert", last_name="Calculus")
+ # The connection is usable again .
+ self.assertEqual(Reporter.objects.count(), 0)
+
@skipUnless(connection.vendor == 'mysql', "MySQL-specific behaviors")
class AtomicMySQLTests(TransactionTestCase):