From 7f6a5fbe2ef26d9970508d5a7236fe009ec274d0 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Tue, 29 Apr 2025 13:42:26 -0400 Subject: [5.2.x] Fixed #36360 -- Fixed QuerySet.update() crash when referring annotations through values(). The issue was only manifesting itself when also filtering againt a related model as that forces the usage of a subquery because SQLUpdateCompiler doesn't support the UPDATE FROM syntax yet. Regression in 65ad4ade74dc9208b9d686a451cd6045df0c9c3a. Refs #28900. Thanks Gav O'Connor for the detailed report. Backport of 8ef4e0bd423ac3764004c73c3d1098e7a51a2945 from main. --- tests/update/tests.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests') diff --git a/tests/update/tests.py b/tests/update/tests.py index 079e00818a..a365dc00c5 100644 --- a/tests/update/tests.py +++ b/tests/update/tests.py @@ -256,6 +256,13 @@ class AdvancedTests(TestCase): 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_values_annotation(self): + RelatedPoint.objects.annotate(abs_id=Abs("id")).filter( + data__is_active=False + ).values("id", "abs_id").update(data=self.d0) + self.r1.refresh_from_db(fields=["data"]) + self.assertEqual(self.r1.data, self.d0) + def test_update_negated_f(self): DataPoint.objects.update(is_active=~F("is_active")) self.assertCountEqual( -- cgit v1.3