diff options
| author | Babak Mahmoudy <babak.mahmoudy@projectfocushq.com> | 2025-04-01 19:34:59 +1100 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-04-02 08:48:02 +0200 |
| commit | b3b09dc6ce72f2aa778b95dc988653bf8c034035 (patch) | |
| tree | 5abe34deb250369dbcf878d5e78203bc8a3d6dc1 | |
| parent | 3fdc8c31da5d5198ee9bdc33a47c70f78bf0d190 (diff) | |
[5.1.x] Fixed #36213 -- Doc'd MySQL's handling of self-select updates in QuerySet.update().
Co-authored-by: Andro Ranogajec <ranogaet@gmail.com>
Backport of be1b776ad8d6f9bccfbdf63f84b16fb81a13119e from main.
| -rw-r--r-- | docs/ref/models/querysets.txt | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 71af4c5882..0ac8964e40 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -2977,6 +2977,14 @@ Using ``update()`` also prevents a race condition wherein something might change in your database in the short period of time between loading the object and calling ``save()``. +.. admonition:: MySQL does not support self-select updates + + On MySQL, ``QuerySet.update()`` may execute a ``SELECT`` followed by an + ``UPDATE`` instead of a single ``UPDATE`` when filtering on related tables, + which can introduce a race condition if concurrent changes occur between + the queries. To ensure atomicity, consider using transactions or avoiding + such filter conditions on MySQL. + Finally, realize that ``update()`` does an update at the SQL level and, thus, does not call any ``save()`` methods on your models, nor does it emit the :attr:`~django.db.models.signals.pre_save` or |
