#33970: select_for_update code snippet example selects for update outside of
it's
transaction
---------------------------------+--------------------------------------
Reporter: Thomas Frössman | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 4.0
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Comment (by Thomas Frössman):
Djangos own test suite almost always does the select_for_update inside a
transaction.atomic even when in places where it isn't technically required
to.
I've had a quick read through them and might be that every instance of
select_for_update is inside a transaction.atomic except when the test is
about failing transaction error.
I see this as a clear indication that it is how code like that should look
as a "best practice".
This is an example from the tests that also doesn't require qs to be
defined bu
{{{
def test_ordered_select_for_update(self):
with transaction.atomic():
qs = Person.objects.filter(
id__in=Person.objects.order_by("-id").select_for_update()
)
self.assertIn("ORDER BY", str(qs.query))
}}}
But sure, do what you want, I won't disturb anymore.
--
Ticket URL: <https://code.djangoproject.com/ticket/33970#comment:4>
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 on the web visit
https://groups.google.com/d/msgid/django-updates/01070182f308b036-b6464f8c-d34d-43cd-ad86-a55935e8f0f8-000000%40eu-central-1.amazonses.com.