diff options
| author | ovalseven8 <8258609+ovalseven8@users.noreply.github.com> | 2018-09-22 15:02:20 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-10-03 15:29:33 -0400 |
| commit | d093e01ec05f661063507503fdf294eb6ee54dee (patch) | |
| tree | 2ddf360d3f475ad0729a76e01ad619458489c2b3 /docs | |
| parent | 18e4ade79ef145401b899ab539322c95d2a64266 (diff) | |
Clarified when QuerySet.select_for_update() locks.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/models/querysets.txt | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index e5d178d34e..d24ac8a859 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -1660,11 +1660,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 |
