summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorabhiabhi94 <13880786+abhiabhi94@users.noreply.github.com>2021-06-26 10:48:38 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-06-29 06:58:46 +0200
commitcd124295d882e13cff556fdeb78e6278d10ac6d5 (patch)
tree8ba77ada80316ca97edc1808f76b8fac4c66435b /docs
parentd79be3ed39b76d3e34431873eec16f6dd354ab17 (diff)
Fixed #32381 -- Made QuerySet.bulk_update() return the number of objects updated.
Co-authored-by: Diego Lima <diego.lima@lais.huol.ufrn.br>
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/querysets.txt12
-rw-r--r--docs/releases/4.0.txt2
2 files changed, 13 insertions, 1 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index 5dc7a6b5bc..1201800567 100644
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -2221,7 +2221,8 @@ normally supports it).
.. method:: bulk_update(objs, fields, batch_size=None)
This method efficiently updates the given fields on the provided model
-instances, generally with one query::
+instances, generally with one query, and returns the number of objects
+updated::
>>> objs = [
... Entry.objects.create(headline='Entry 1'),
@@ -2230,6 +2231,11 @@ instances, generally with one query::
>>> objs[0].headline = 'This is entry 1'
>>> objs[1].headline = 'This is entry 2'
>>> Entry.objects.bulk_update(objs, ['headline'])
+ 2
+
+.. versionchanged:: 4.0
+
+ The return value of the number of objects updated was added.
:meth:`.QuerySet.update` is used to save the changes, so this is more efficient
than iterating through the list of models and calling ``save()`` on each of
@@ -2246,6 +2252,10 @@ them, but it has a few caveats:
extra query per ancestor.
* When an individual batch contains duplicates, only the first instance in that
batch will result in an update.
+* The number of objects updated returned by the function may be fewer than the
+ number of objects passed in. This can be due to duplicate objects passed in
+ which are updated in the same batch or race conditions such that objects are
+ no longer present in the database.
The ``batch_size`` parameter controls how many objects are saved in a single
query. The default is to update all objects in one batch, except for SQLite
diff --git a/docs/releases/4.0.txt b/docs/releases/4.0.txt
index 9b57a524aa..a9b29d7ce4 100644
--- a/docs/releases/4.0.txt
+++ b/docs/releases/4.0.txt
@@ -263,6 +263,8 @@ Models
* :class:`~django.db.models.DurationField` now supports multiplying and
dividing by scalar values on SQLite.
+* :meth:`.QuerySet.bulk_update` now returns the number of objects updated.
+
Requests and Responses
~~~~~~~~~~~~~~~~~~~~~~