1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #34421 -- Fixed QuerySet.update() on querysets in descending order by annotations.

This commit is contained in:
hb6h057
2023-03-17 00:03:32 +08:00
committed by Mariusz Felisiak
parent d2b688b966
commit 2ffa815c73
3 changed files with 24 additions and 1 deletions

View File

@@ -249,6 +249,13 @@ class AdvancedTests(TestCase):
Bar.objects.annotate(abs_id=Abs("m2m_foo")).order_by("abs_id").update(x=3)
self.assertEqual(Bar.objects.get().x, 3)
def test_update_ordered_by_m2m_annotation_desc(self):
foo = Foo.objects.create(target="test")
Bar.objects.create(foo=foo)
Bar.objects.annotate(abs_id=Abs("m2m_foo")).order_by("-abs_id").update(x=4)
self.assertEqual(Bar.objects.get().x, 4)
def test_update_negated_f(self):
DataPoint.objects.update(is_active=~F("is_active"))
self.assertCountEqual(
@@ -309,6 +316,14 @@ class MySQLUpdateOrderByTest(TestCase):
)
self.assertEqual(updated, 2)
def test_order_by_update_on_unique_constraint_annotation_desc(self):
updated = (
UniqueNumber.objects.annotate(number_annotation=F("number"))
.order_by("-number_annotation")
.update(number=F("number") + 1)
)
self.assertEqual(updated, 2)
def test_order_by_update_on_parent_unique_constraint(self):
# Ordering by inherited fields is omitted because joined fields cannot
# be used in the ORDER BY clause.