#32388: bulk_update doesn't necessarily ignore duplicates
-------------------------------------+-------------------------------------
Reporter: Tim | Owner: nobody
McCurrach |
Type: Bug | Status: new
Component: Database | Version: 3.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
In the
[https://docs.djangoproject.com/en/3.1/ref/models/querysets/#django.db.models.query.QuerySet.bulk_update
docs for bulk_update] it says: "If objs contains duplicates, only the
first one is updated." This is due to the way the query is constructed.
However this is only true for each SQL update. And if there are duplicates
that fall into different batches, they will both (or all) be used as part
of the update.
=== To Reproduce Error ===
{{{
>>> m1 = MyModel.objects.get(id=1)
>>> m2 = MyModel.objects.get(id=1)
>>> m1.name="a"
>>> m2.name="b"
>>> MyModel.objects.bulk_update([m1, m2], ['name'], batch_size=1)
>>> MyModel.objects.get(id=1).name
'b'
}}}
Whilst the above is an extreme example, it demonstrates the point. If a
large number of objects are being updated, you cannot currently rely on
the behaviour that only the first instance of a duplicate will affect the
update.
--
Ticket URL: <https://code.djangoproject.com/ticket/32388>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/056.fbbd6557a8f6164eb7ffdee6037b074a%40djangoproject.com.