#36398: select_for_update(of=...) ignores "self" when using values_list() when
not
selecting a column from the model
-------------------------------------+-------------------------------------
Reporter: OutOfFocus4 | Owner:
| JakeWalson
Type: Bug | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Shai Berger):
* cc: Shai Berger (added)
Comment:
While the code provided in the attached tests can be used to reproduce the
problem, only the second test fails, and its failure is a "second order
result" -- an error trying to lock the nullable side of a join, when
Django was explicitly asked to lock only the non-nullable side, but
ignored the request.
This change causes an existing test to fail, on the immediate cause, and
so I think it is useful as a step towards resolving this ticket.
{{{#!diff
diff --git a/tests/select_for_update/tests.py
b/tests/select_for_update/tests.py
index 460e279770..f022b179be 100644
--- a/tests/select_for_update/tests.py
+++ b/tests/select_for_update/tests.py
@@ -284,13 +284,23 @@ class SelectForUpdateTests(TransactionTestCase):
select_for_update(of=['self']) when the only columns selected are
from
related tables.
"""
- with transaction.atomic():
+ with transaction.atomic(), CaptureQueriesContext(connection) as
ctx:
values = list(
- Person.objects.select_related("born")
+ Person.objects # Note: select_related() is canceled by
values()
.select_for_update(of=("self",))
.values("born__name")
)
self.assertEqual(values, [{"born__name": self.city1.name}])
+ # Check for #36398 -- locking is limited to self
+ features = connections["default"].features
+ if features.select_for_update_of_column:
+ expected = [
+ 'select_for_update_person"."id',
+ ]
+ else:
+ expected = ["select_for_update_person"]
+ 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",
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36398#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/01070199693fef5e-09e0b003-8bec-4bbf-bc68-4d06bc9e79f3-000000%40eu-central-1.amazonses.com.