#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 Mariusz Felisiak):

 Replying to [comment:2 Thomas Frössman]:
 > Even if this isn't a hard bug would it not still make sense to move the
 select statement inside the transaction it logically belongs in the code
 snippet?
 >
 > I would probably request a change to that piece of code in a code review
 99% of all use cases.  In fact I did find code like this out in the wile
 just now and the only reason I could track it down why someone would write
 it like that is that the manual gives this example.

 The code is correct. There is no need to create and to be in an atomic
 transaction while querysets are prepared. I see no reason to change this
 example, TBH. It's also explained in details in docs:

 > ''"When the queryset is evaluated (`for entry in entries` in this case),
 all matched entries will be locked until the end of the transaction block,
 meaning that other transactions will be prevented from changing or
 acquiring locks on them."''

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33970#comment:3>
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/01070182f2d1aedb-a930dfa7-9f15-465c-8bd4-d95707961608-000000%40eu-central-1.amazonses.com.

Reply via email to