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

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 65ad4ade74.

Refs #28900.

Thanks Gav O'Connor for the detailed report.
This commit is contained in:
Simon Charette
2025-04-29 13:42:26 -04:00
committed by Sarah Boyce
parent 27ffccc96b
commit 8ef4e0bd42
3 changed files with 14 additions and 2 deletions

View File

@@ -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(