summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorShai Berger <shai@platonix.com>2014-03-30 20:03:35 +0300
committerShai Berger <shai@platonix.com>2014-04-10 01:44:30 +0300
commit3a9a4570efc933a50efec27bdd06af11877eeac6 (patch)
treea64bf01fe5d9bbe713f19c825ae85177f7b1d5cf /tests
parentf6f188ffc7d48f7f38edea35234f23f2cfefda0b (diff)
[1.7.x] Fixed #22343 -- Disallowed select_for_update in autocommit mode
The ticket was originally about two failing tests, which are fixed by putting their queries in transactions. Thanks Tim Graham for the report, Aymeric Augustin for the fix, and Simon Charette, Tim Graham & Loïc Bistuer for review. Backport of b990df1d63 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/select_for_update/tests.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/select_for_update/tests.py b/tests/select_for_update/tests.py
index 278458ed39..5d126844d2 100644
--- a/tests/select_for_update/tests.py
+++ b/tests/select_for_update/tests.py
@@ -134,6 +134,34 @@ class SelectForUpdateTests(TransactionTestCase):
Person.objects.all().select_for_update(nowait=True)
)
+ @skipUnlessDBFeature('has_select_for_update')
+ def test_for_update_requires_transaction(self):
+ """
+ Test that a TransactionManagementError is raised
+ when a select_for_update query is executed outside of a transaction.
+ """
+ transaction.set_autocommit(True)
+ try:
+ with self.assertRaises(transaction.TransactionManagementError):
+ list(Person.objects.all().select_for_update())
+ finally:
+ transaction.set_autocommit(True)
+
+ @skipUnlessDBFeature('has_select_for_update')
+ def test_for_update_requires_transaction_only_in_execution(self):
+ """
+ Test that no TransactionManagementError is raised
+ when select_for_update is invoked outside of a transaction -
+ only when the query is executed.
+ """
+ transaction.set_autocommit(True)
+ try:
+ people = Person.objects.all().select_for_update()
+ with self.assertRaises(transaction.TransactionManagementError):
+ list(people)
+ finally:
+ transaction.set_autocommit(True)
+
def run_select_for_update(self, status, nowait=False):
"""
Utility method that runs a SELECT FOR UPDATE against all