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 Tim Graham, 6 years ago

Cc: Tom Forbes added
Component: UtilitiesDatabase layer (models, ORM)
Summary: django/db/models/query.py bulk_update doesn't check if objs passed by params have duplicationQuerySet.bulk_update() doesn't check if objs argument contains duplicates
Type: BugCleanup/optimization

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?

comment:3 by Tom Forbes, 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 Tim Graham, 6 years ago

Triage Stage: UnreviewedAccepted

comment:5 by Hasan Ramezani, 6 years ago

Has patch: set
Owner: changed from nobody to Hasan Ramezani
Status: newassigned

comment:7 by Tim Graham, 6 years ago

Component: Database layer (models, ORM)Documentation
Summary: QuerySet.bulk_update() doesn't check if objs argument contains duplicatesDocument that QuerySet.bulk_update() doesn't check if objs contains duplicates
Triage Stage: AcceptedReady for checkin

comment:8 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 52d06d3:

Fixed #29968 -- Doc'd that QuerySet.bulk_update() doesn't check for duplicates.

Note: See TracTickets for help on using tickets.
Back to Top