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 /docs/ref | |
| parent | 46509cf13dbf049f75077981c29ef2c60b5a96ab (diff) | |
Fixed #26500 -- Added SKIP LOCKED support to select_for_update().
Thanks Tim for the review.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/databases.txt | 6 | ||||
| -rw-r--r-- | docs/ref/models/querysets.txt | 23 |
2 files changed, 18 insertions, 11 deletions
diff --git a/docs/ref/databases.txt b/docs/ref/databases.txt index 35a3dbcbe8..983b7525c3 100644 --- a/docs/ref/databases.txt +++ b/docs/ref/databases.txt @@ -569,9 +569,9 @@ both MySQL and Django will attempt to convert the values from UTC to local time. Row locking with ``QuerySet.select_for_update()`` ------------------------------------------------- -MySQL does not support the ``NOWAIT`` option to the ``SELECT ... FOR UPDATE`` -statement. If ``select_for_update()`` is used with ``nowait=True`` then a -``DatabaseError`` will be raised. +MySQL does not support the ``NOWAIT`` and ``SKIP LOCKED`` options to the +``SELECT ... FOR UPDATE`` statement. If ``select_for_update()`` is used with +``nowait=True`` or ``skip_locked=True`` then a ``DatabaseError`` will be raised. Automatic typecasting can cause unexpected results -------------------------------------------------- diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 3f4fce1a26..8d2e3ebb3b 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -1528,7 +1528,7 @@ For example:: ``select_for_update()`` ~~~~~~~~~~~~~~~~~~~~~~~ -.. method:: select_for_update(nowait=False) +.. method:: select_for_update(nowait=False, skip_locked=False) Returns a queryset that will lock rows until the end of the transaction, generating a ``SELECT ... FOR UPDATE`` SQL statement on supported databases. @@ -1546,16 +1546,19 @@ selected rows, the query will block until the lock is released. If this is not the behavior you want, call ``select_for_update(nowait=True)``. This will make the call non-blocking. If a conflicting lock is already acquired by another transaction, :exc:`~django.db.DatabaseError` will be raised when the -queryset is evaluated. +queryset is evaluated. You can also ignore locked rows by using +``select_for_update(skip_locked=True)`` instead. The ``nowait`` and +``skip_locked`` are mutually exclusive and attempts to call +``select_for_update()`` with both options enabled will result in a +:exc:`ValueError`. Currently, the ``postgresql``, ``oracle``, and ``mysql`` database -backends support ``select_for_update()``. However, MySQL has no support for the -``nowait`` argument. Obviously, users of external third-party backends should -check with their backend's documentation for specifics in those cases. +backends support ``select_for_update()``. However, MySQL doesn't support the +``nowait`` and ``skip_locked`` arguments. -Passing ``nowait=True`` to ``select_for_update()`` using database backends that -do not support ``nowait``, such as MySQL, will cause a -:exc:`~django.db.DatabaseError` to be raised. This is in order to prevent code +Passing ``nowait=True`` or ``skip_locked=True`` to ``select_for_update()`` +using database backends that do not support these options, such as MySQL, will +cause a :exc:`~django.db.DatabaseError` to be raised. This prevents code from unexpectedly blocking. Evaluating a queryset with ``select_for_update()`` in autocommit mode on @@ -1580,6 +1583,10 @@ raised if ``select_for_update()`` is used in autocommit mode. ``select_for_update()`` you should use :class:`~django.test.TransactionTestCase`. +.. versionchanged:: 1.11 + + The ``skip_locked`` argument was added. + ``raw()`` ~~~~~~~~~ |
