Fixed #30953 -- Made select_for_update() lock queryset's model when using "self" with multi-table inheritance.

Thanks Abhijeet Viswa for the report and initial patch.
This commit is contained in:
Mariusz Felisiak 2019-12-02 07:57:19 +01:00 committed by GitHub
parent c33eb6dcd0
commit 0107e3d105
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 135 additions and 19 deletions

View file

@ -1692,6 +1692,14 @@ 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.
.. admonition:: Lock parents models in ``select_for_update(of=(...))``
If you want to lock parents models when using :ref:`multi-table inheritance
<multi-table-inheritance>`, you must specify parent link fields (by default
``<parent_model_name>_ptr``) in the ``of`` argument. For example::
Restaurant.objects.select_for_update(of=('self', 'place_ptr'))
You can't use ``select_for_update()`` on nullable relations::
>>> Person.objects.select_related('hometown').select_for_update()