1
0
mirror of https://github.com/django/django.git synced 2025-10-25 06:36:07 +00:00

Fixed #36301 -- Fixed select_for_update(of) crash when using values()/values_list().

Regression in 65ad4ade74 which allowed for
annotations to be SELECT'ed before model field references through
values()/values_list() and broke assumptions the select_for_update(of)
table infererence logic had about model fields always being first.

Refs #28900.

Thanks OutOfFocus4 for the report and Sarah for the test.
This commit is contained in:
Simon Charette
2025-04-04 14:42:31 -04:00
committed by Mariusz Felisiak
parent 8ad3e80e88
commit 71a19a0e47
3 changed files with 27 additions and 11 deletions

View File

@@ -13,6 +13,8 @@ from django.db import (
router,
transaction,
)
from django.db.models import F, Value
from django.db.models.functions import Concat
from django.test import (
TransactionTestCase,
override_settings,
@@ -149,6 +151,15 @@ class SelectForUpdateTests(TransactionTestCase):
expected = [connection.ops.quote_name(value) for value in expected]
self.assertTrue(self.has_for_update_sql(ctx.captured_queries, of=expected))
@skipUnlessDBFeature("has_select_for_update_of")
def test_for_update_of_values_list(self):
queries = Person.objects.select_for_update(
of=("self",),
).values_list(Concat(Value("Dr. "), F("name")), "born")
with transaction.atomic():
values = queries.get(pk=self.person.pk)
self.assertSequenceEqual(values, ("Dr. Reinhardt", self.city1.pk))
@skipUnlessDBFeature("has_select_for_update_of")
def test_for_update_sql_model_inheritance_generated_of(self):
with transaction.atomic(), CaptureQueriesContext(connection) as ctx: