Fixed #27193 -- Preserved ordering in select_for_update subqueries.

This commit is contained in:
François Freitag 2016-09-28 22:39:50 -07:00 committed by Tim Graham
parent 9e26a8331d
commit 8ac115c730
2 changed files with 14 additions and 2 deletions

View file

@ -300,3 +300,12 @@ class SelectForUpdateTests(TransactionTestCase):
def test_nowait_and_skip_locked(self):
with self.assertRaisesMessage(ValueError, 'The nowait option cannot be used with skip_locked.'):
Person.objects.select_for_update(nowait=True, skip_locked=True)
def test_ordered_select_for_update(self):
"""
Subqueries should respect ordering as an ORDER BY clause may be useful
to specify a row locking order to prevent deadlocks (#27193).
"""
with transaction.atomic():
qs = Person.objects.filter(id__in=Person.objects.order_by('-id').select_for_update())
self.assertIn('ORDER BY', str(qs.query))