diff options
| author | Simon Charette <charette.s@gmail.com> | 2025-04-04 14:42:31 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2025-04-07 22:56:40 +0200 |
| commit | 71a19a0e475165dbc14c1fe02f552013ee670e4c (patch) | |
| tree | 3f0178e34807741aba98cbdf82e82c693c9e9940 /tests/select_for_update | |
| parent | 8ad3e80e88201f4c557f6fa79fcfc0f8a0961830 (diff) | |
Fixed #36301 -- Fixed select_for_update(of) crash when using values()/values_list().
Regression in 65ad4ade74dc9208b9d686a451cd6045df0c9c3a 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.
Diffstat (limited to 'tests/select_for_update')
| -rw-r--r-- | tests/select_for_update/tests.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/select_for_update/tests.py b/tests/select_for_update/tests.py index e8ba8f8b6e..1bc87113ba 100644 --- a/tests/select_for_update/tests.py +++ b/tests/select_for_update/tests.py @@ -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, @@ -150,6 +152,15 @@ class SelectForUpdateTests(TransactionTestCase): 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: list(EUCountry.objects.select_for_update(of=("self",))) |
