summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorovalseven8 <8258609+ovalseven8@users.noreply.github.com>2018-09-22 15:02:20 +0200
committerTim Graham <timograham@gmail.com>2018-10-03 15:35:20 -0400
commit9e5f4bcedb435e05e40720d76678b6266ae20c89 (patch)
tree2e1583562c420412e39bd4829aa0902fae2602ba /docs
parent173e242d715da1eedce2540f8531b9c446177a16 (diff)
[2.1.x] Clarified when QuerySet.select_for_update() locks.
Backport of d093e01ec05f661063507503fdf294eb6ee54dee from master.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/querysets.txt12
1 files changed, 9 insertions, 3 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index 98646d5344..609a87097a 100644
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -1664,11 +1664,17 @@ generating a ``SELECT ... FOR UPDATE`` SQL statement on supported databases.
For example::
+ from django.db import transaction
+
entries = Entry.objects.select_for_update().filter(author=request.user)
+ with transaction.atomic():
+ for entry in entries:
+ ...
-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.
+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