Fixed #26500 -- Added SKIP LOCKED support to select_for_update().

Thanks Tim for the review.
This commit is contained in:
Simon Charette 2016-06-23 11:52:14 -04:00
parent 46509cf13d
commit b8e6e1b43b
No known key found for this signature in database
GPG key ID: 72AF89A0B1B4EDB3
11 changed files with 98 additions and 27 deletions

View file

@ -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):