#36301: select_for_update(of) crash when used with values_list since Django 5.2 on
Postgres
-------------------------------------+-------------------------------------
Reporter: Simon | Owner: Simon Charette
Charette |
Type: Bug | Status: assigned
Component: Database | Version: 5.2
layer (models, ORM) |
Severity: Release | Keywords:
blocker |
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
This was extracted from #36299 as a distinct issue.
-----
Queryset evaluation raises an `AttributeError` if the database backend
supports `SELECT ... FOR UPDATE`. The following code:
{{{#!python
with atomic():
values = (
User.objects.select_for_update(of=("self",))
.values_list(
Concat(F("first_name"), Value(" "), F("last_name")), "email"
)
.get(pk=12)
)
}}}
will fail with a stacktrace ending in `AttributeError: 'Concat' object has
no attribute 'target'` using the Postgresql DB backend.
Replicate by Sarah as a regression in
65ad4ade74dc9208b9d686a451cd6045df0c9c3a
{{{#!diff
diff --git a/tests/select_for_update/tests.py
b/tests/select_for_update/tests.py
index e8ba8f8b6e..18fca277cb 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,
@@ -122,6 +124,17 @@ class SelectForUpdateTests(TransactionTestCase):
list(Person.objects.select_for_update(no_key=True))
self.assertIs(self.has_for_update_sql(ctx.captured_queries,
no_key=True), True)
+ @skipUnlessDBFeature("has_select_for_update_of")
+ def test_for_update_of_values_list(self):
+ with transaction.atomic():
+ values = (
+ Person.objects.select_for_update(
+ of=("self",),
+ )
+ .values_list(Concat(Value("Dr. "), F("name")), "born")
+ ).get(pk=
self.person.pk)
+ self.assertTupleEqual(values, ("Dr. Reinhardt",
self.city1.pk))
+
@skipUnlessDBFeature("has_select_for_update_of")
}}}
--
Ticket URL: <
https://code.djangoproject.com/ticket/36301>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.