diff options
| author | hb6h057 <me@hb6.org> | 2023-03-17 00:03:32 +0800 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-03-18 13:19:40 +0100 |
| commit | 2ffa815c734e12262a3cb8ce5664f297128ae47f (patch) | |
| tree | ac8f356d2de02b6593444d9fe568ab4b31940c04 /tests/update | |
| parent | d2b688b966f5d30414899549412d370e1317ddb8 (diff) | |
Fixed #34421 -- Fixed QuerySet.update() on querysets in descending order by annotations.
Diffstat (limited to 'tests/update')
| -rw-r--r-- | tests/update/tests.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/update/tests.py b/tests/update/tests.py index e88eeda96d..079e00818a 100644 --- a/tests/update/tests.py +++ b/tests/update/tests.py @@ -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. |
