Clarified when QuerySet.select_for_update() locks.

This commit is contained in:
ovalseven8 2018-09-22 15:02:20 +02:00 committed by Tim Graham
parent 18e4ade79e
commit d093e01ec0
1 changed files with 10 additions and 4 deletions

View File

@ -1660,11 +1660,17 @@ generating a ``SELECT ... FOR UPDATE`` SQL statement on supported databases.
For example:: 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, entries = Entry.objects.select_for_update().filter(author=request.user)
meaning that other transactions will be prevented from changing or acquiring with transaction.atomic():
locks on them. 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 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 selected rows, the query will block until the lock is released. If this is