mirror of https://github.com/django/django.git
[2.1.x] Clarified when QuerySet.select_for_update() locks.
Backport of d093e01ec0
from master.
This commit is contained in:
parent
173e242d71
commit
9e5f4bcedb
|
@ -1664,11 +1664,17 @@ generating a ``SELECT ... FOR UPDATE`` SQL statement on supported databases.
|
|||
|
||||
For example::
|
||||
|
||||
entries = Entry.objects.select_for_update().filter(author=request.user)
|
||||
from django.db import transaction
|
||||
|
||||
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.
|
||||
entries = Entry.objects.select_for_update().filter(author=request.user)
|
||||
with transaction.atomic():
|
||||
for entry in entries:
|
||||
...
|
||||
|
||||
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.
|
||||
|
||||
Usually, if another transaction has already acquired a lock on one of the
|
||||
selected rows, the query will block until the lock is released. If this is
|
||||
|
|
Loading…
Reference in New Issue