diff options
| author | Simon Charette <charette.s@gmail.com> | 2016-06-23 11:52:14 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2016-08-08 12:01:43 -0400 |
| commit | b8e6e1b43b0bccec178dcc6708c5c8295abfb2e5 (patch) | |
| tree | f3c146f02ecf6b0181d790cc67d83ad53cd629f9 /django/db/models/sql | |
| parent | 46509cf13dbf049f75077981c29ef2c60b5a96ab (diff) | |
Fixed #26500 -- Added SKIP LOCKED support to select_for_update().
Thanks Tim for the review.
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/compiler.py | 11 | ||||
| -rw-r--r-- | django/db/models/sql/query.py | 2 |
2 files changed, 9 insertions, 4 deletions
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index cedb140143..5eaac1fc74 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -445,13 +445,16 @@ class SQLCompiler(object): "select_for_update cannot be used outside of a transaction." ) - # If we've been asked for a NOWAIT query but the backend does - # not support it, raise a DatabaseError otherwise we could get - # an unexpected deadlock. nowait = self.query.select_for_update_nowait + skip_locked = self.query.select_for_update_skip_locked + # If we've been asked for a NOWAIT/SKIP LOCKED query but the + # backend does not support it, raise a DatabaseError otherwise + # we could get an unexpected deadlock. if nowait and not self.connection.features.has_select_for_update_nowait: raise DatabaseError('NOWAIT is not supported on this database backend.') - result.append(self.connection.ops.for_update_sql(nowait=nowait)) + elif skip_locked and not self.connection.features.has_select_for_update_skip_locked: + raise DatabaseError('SKIP LOCKED is not supported on this database backend.') + result.append(self.connection.ops.for_update_sql(nowait=nowait, skip_locked=skip_locked)) return ' '.join(result), tuple(params) finally: diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index d182242ce4..426087f8af 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -167,6 +167,7 @@ class Query(object): self.distinct_fields = [] self.select_for_update = False self.select_for_update_nowait = False + self.select_for_update_skip_locked = False self.select_related = False # Arbitrary limit for select_related to prevents infinite recursion. @@ -286,6 +287,7 @@ class Query(object): obj.distinct_fields = self.distinct_fields[:] obj.select_for_update = self.select_for_update obj.select_for_update_nowait = self.select_for_update_nowait + obj.select_for_update_skip_locked = self.select_for_update_skip_locked obj.select_related = self.select_related obj.values_select = self.values_select[:] obj._annotations = self._annotations.copy() if self._annotations is not None else None |
