summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2017-06-29 23:00:15 +0300
committerTim Graham <timograham@gmail.com>2017-06-29 16:00:15 -0400
commitb9f7dce84b7ab5e198129030eae6c1a4aec83d24 (patch)
tree8f350d29029e977c48107db898a6994c38cbfba4 /docs
parent2d18c60fbb1efcc980adfe875dadb02c749da509 (diff)
Fixed #28010 -- Added FOR UPDATE OF support to QuerySet.select_for_update().
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/databases.txt6
-rw-r--r--docs/ref/models/querysets.txt23
-rw-r--r--docs/releases/2.0.txt11
3 files changed, 31 insertions, 9 deletions
diff --git a/docs/ref/databases.txt b/docs/ref/databases.txt
index 45b1772514..69921f437b 100644
--- a/docs/ref/databases.txt
+++ b/docs/ref/databases.txt
@@ -629,9 +629,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`` 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
+MySQL does not support the ``NOWAIT``, ``SKIP LOCKED``, and ``OF`` options to
+the ``SELECT ... FOR UPDATE`` statement. If ``select_for_update()`` is used
+with ``nowait=True``, ``skip_locked=True``, or ``of`` then a
:exc:`~django.db.NotSupportedError` is raised.
Automatic typecasting can cause unexpected results
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index a9006a14a9..d8d063a7a5 100644
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -1611,7 +1611,7 @@ For example::
``select_for_update()``
~~~~~~~~~~~~~~~~~~~~~~~
-.. method:: select_for_update(nowait=False, skip_locked=False)
+.. method:: select_for_update(nowait=False, skip_locked=False, of=())
Returns a queryset that will lock rows until the end of the transaction,
generating a ``SELECT ... FOR UPDATE`` SQL statement on supported databases.
@@ -1635,14 +1635,21 @@ queryset is evaluated. You can also ignore locked rows by using
``select_for_update()`` with both options enabled will result in a
:exc:`ValueError`.
+By default, ``select_for_update()`` locks all rows that are selected by the
+query. For example, rows of related objects specified in :meth:`select_related`
+are locked in addition to rows of the queryset's model. If this isn't desired,
+specify the related objects you want to lock in ``select_for_update(of=(...))``
+using the same fields syntax as :meth:`select_related`. Use the value ``'self'``
+to refer to the queryset's model.
+
Currently, the ``postgresql``, ``oracle``, and ``mysql`` database
backends support ``select_for_update()``. However, MySQL doesn't support the
-``nowait`` and ``skip_locked`` arguments.
+``nowait``, ``skip_locked``, and ``of`` arguments.
-Passing ``nowait=True`` or ``skip_locked=True`` to ``select_for_update()``
-using database backends that do not support these options, such as MySQL,
-raises a :exc:`~django.db.NotSupportedError`. This prevents code from
-unexpectedly blocking.
+Passing ``nowait=True``, ``skip_locked=True``, or ``of`` to
+``select_for_update()`` using database backends that do not support these
+options, such as MySQL, raises a :exc:`~django.db.NotSupportedError`. This
+prevents code from unexpectedly blocking.
Evaluating a queryset with ``select_for_update()`` in autocommit mode on
backends which support ``SELECT ... FOR UPDATE`` is a
@@ -1670,6 +1677,10 @@ raised if ``select_for_update()`` is used in autocommit mode.
The ``skip_locked`` argument was added.
+.. versionchanged:: 2.0
+
+ The ``of`` argument was added.
+
``raw()``
~~~~~~~~~
diff --git a/docs/releases/2.0.txt b/docs/releases/2.0.txt
index 078cbbdf2c..8dfc43c24d 100644
--- a/docs/releases/2.0.txt
+++ b/docs/releases/2.0.txt
@@ -252,6 +252,12 @@ Models
:class:`~django.db.models.functions.datetime.Extract` now works with
:class:`~django.db.models.DurationField`.
+* Added the ``of`` argument to :meth:`.QuerySet.select_for_update()`, supported
+ on PostgreSQL and Oracle, to lock only rows from specific tables rather than
+ all selected tables. It may be helpful particularly when
+ :meth:`~.QuerySet.select_for_update()` is used in conjunction with
+ :meth:`~.QuerySet.select_related()`.
+
Requests and Responses
~~~~~~~~~~~~~~~~~~~~~~
@@ -331,6 +337,11 @@ backends.
* The first argument of ``SchemaEditor._create_index_name()`` is now
``table_name`` rather than ``model``.
+* To enable ``FOR UPDATE OF`` support, set
+ ``DatabaseFeatures.has_select_for_update_of = True``. If the database
+ requires that the arguments to ``OF`` be columns rather than tables, set
+ ``DatabaseFeatures.select_for_update_of_column = True``.
+
Dropped support for Oracle 11.2
-------------------------------