summaryrefslogtreecommitdiff
path: root/tests/transactions
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 20:57:43 +0200
commit25860096f981b0b3026b38329e4b69c72b1d8db9 (patch)
tree1b80625f1d9c466295ae457a0ff60fb4902ca9f8 /tests/transactions
parent3becac84845cee8f12a5fb7f68c87cbaf029c6a0 (diff)
downloaddjango-25860096f981b0b3026b38329e4b69c72b1d8db9.tar.gz
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.
Diffstat (limited to 'tests/transactions')
-rw-r--r--tests/transactions/tests.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py
index 3ca6a22ecf..72e600d41d 100644
--- a/tests/transactions/tests.py
+++ b/tests/transactions/tests.py
@@ -9,8 +9,8 @@ import time
from unittest import skipIf, skipUnless
from django.db import (connection, transaction,
- DatabaseError, IntegrityError, OperationalError)
-from django.test import TransactionTestCase, skipIfDBFeature
+ DatabaseError, Error, IntegrityError, OperationalError)
+from django.test import TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature
from django.utils import six
from .models import Reporter
@@ -338,6 +338,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):