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.
* owner: nobody => Tim McCurrach
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/32388#comment:1>
* type: Bug => Cleanup/optimization
* component: Database layer (models, ORM) => Documentation
* easy: 0 => 1
* stage: Unreviewed => Accepted
Comment:
I don't think it is worth additional complexity (see #29968), we can
clarify this in docs, e.g.
{{{
If ``objs`` contains duplicates in a batch, only the first one is updated.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32388#comment:2>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"241da3f06ee0c6f436341cda5890b221ac453e3b" 241da3f0]:
{{{
#!CommitTicketReference repository=""
revision="241da3f06ee0c6f436341cda5890b221ac453e3b"
Fixed #32388 -- Clarified QuerySet.bulk_update() caveat about duplicates
for multiple batches.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32388#comment:3>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"e95a60bb64b2c78f025a44972e7d646fa8c85b2b" e95a60b]:
{{{
#!CommitTicketReference repository=""
revision="e95a60bb64b2c78f025a44972e7d646fa8c85b2b"
[3.2.x] Fixed #32388 -- Clarified QuerySet.bulk_update() caveat about
duplicates for multiple batches.
Backport of 241da3f06ee0c6f436341cda5890b221ac453e3b from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32388#comment:4>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"b920945d0286673e5374dee60d329e5d2d1127cd" b920945d]:
{{{
#!CommitTicketReference repository=""
revision="b920945d0286673e5374dee60d329e5d2d1127cd"
[3.1.x] Fixed #32388 -- Clarified QuerySet.bulk_update() caveat about
duplicates for multiple batches.
Backport of 241da3f06ee0c6f436341cda5890b221ac453e3b from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32388#comment:5>