Opened 6 years ago
Closed 6 years ago
#29968 closed Cleanup/optimization (fixed)
Document that QuerySet.bulk_update() doesn't check if objs contains duplicates
Reported by: | lyl-lucas | Owned by: | Hasan Ramezani |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Tom Forbes | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
bulk_update method at master branch, the param objs
is a list. if objs
have the duplicated obj in it, it will only update depend on the lower-index obj. if it needs to consider raise Exception when it comes to this situation?
def bulk_update(self, objs, fields, batch_size=None): """ Update the given fields in each of the given objects in the database. """
Change History (6)
comment:1 by , 6 years ago
Cc: | added |
---|---|
Component: | Utilities → Database layer (models, ORM) |
Summary: | django/db/models/query.py bulk_update doesn't check if objs passed by params have duplication → QuerySet.bulk_update() doesn't check if objs argument contains duplicates |
Type: | Bug → Cleanup/optimization |
comment:3 by , 6 years ago
We do already check that all primary keys are set, which adds overhead, and we could use some set operations here to find duplicate primary keys as well as ones missing primary keys in a single operation?
I'm partly inclined to just say it's a documentation issue and fix it there, the behavior could be pretty confusing and it's not that expensive to fail loudly.
comment:4 by , 6 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:7 by , 6 years ago
Component: | Database layer (models, ORM) → Documentation |
---|---|
Summary: | QuerySet.bulk_update() doesn't check if objs argument contains duplicates → Document that QuerySet.bulk_update() doesn't check if objs contains duplicates |
Triage Stage: | Accepted → Ready for checkin |
I'm not sure if that will be a mistake common enough to add some protection against (considering that all checks have some performance costs). How did you run into it?