Fixed #32888 -- Doc'd that select_for_update() only locks tables with selected columns.

This commit is contained in:
Hannes Ljungberg 2021-10-04 10:20:34 +02:00 committed by GitHub
parent a3185a6701
commit d400b08a8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -1773,6 +1773,12 @@ to refer to the queryset's model.
Restaurant.objects.select_for_update(of=('self', 'place_ptr')) Restaurant.objects.select_for_update(of=('self', 'place_ptr'))
.. admonition:: Using ``select_for_update(of=(...))`` with specified fields
If you want to lock models and specify selected fields, e.g. using
:meth:`values`, you must select at least one field from each model in the
``of`` argument. Models without selected fields will not be locked.
On PostgreSQL only, you can pass ``no_key=True`` in order to acquire a weaker On PostgreSQL only, you can pass ``no_key=True`` in order to acquire a weaker
lock, that still allows creating rows that merely reference locked rows lock, that still allows creating rows that merely reference locked rows
(through a foreign key, for example) while the lock is in place. The (through a foreign key, for example) while the lock is in place. The