mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
Fixed #26500 -- Added SKIP LOCKED support to select_for_update().
Thanks Tim for the review.
This commit is contained in:
parent
46509cf13d
commit
b8e6e1b43b
11 changed files with 98 additions and 27 deletions
|
@ -835,15 +835,18 @@ class QuerySet(object):
|
|||
else:
|
||||
return self._filter_or_exclude(None, **filter_obj)
|
||||
|
||||
def select_for_update(self, nowait=False):
|
||||
def select_for_update(self, nowait=False, skip_locked=False):
|
||||
"""
|
||||
Returns a new QuerySet instance that will select objects with a
|
||||
FOR UPDATE lock.
|
||||
"""
|
||||
if nowait and skip_locked:
|
||||
raise ValueError('The nowait option cannot be used with skip_locked.')
|
||||
obj = self._clone()
|
||||
obj._for_write = True
|
||||
obj.query.select_for_update = True
|
||||
obj.query.select_for_update_nowait = nowait
|
||||
obj.query.select_for_update_skip_locked = skip_locked
|
||||
return obj
|
||||
|
||||
def select_related(self, *fields):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue