Opened 5 years ago

Closed 5 years ago

#31474 closed Cleanup/optimization (fixed)

QuerySet.Delete - inconsistent result when zero objects deleted

Reported by: Adi Gabaie Owned by: Hasan Ramezani
Component: Database layer (models, ORM) Version: 2.2
Severity: Normal Keywords: querySet Delete counter
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The result format of the QuerySet.Delete method is a tuple: (X, Y)
X - is the total amount of deleted objects (including foreign key deleted objects)
Y - is a dictionary specifying counters of deleted objects for each specific model (the key is the _meta.label of the model and the value is counter of deleted objects of this model).

Example: <class 'tuple'>: (2, {'my_app.FileAccess': 1, 'my_app.File': 1})

When there are zero objects to delete in total - the result is inconsistent:

  • For models with foreign keys - the result will be: <class 'tuple'>: (0, {})
  • For "simple" models without foreign key - the result will be: <class 'tuple'>: (0, {'my_app.BlockLibrary': 0})

I would expect there will be no difference between the two cases: Either both will have the empty dictionary OR both will have dictionary with model-label keys and zero value.

Change History (6)

comment:1 by Adi Gabaie, 5 years ago

Type: UncategorizedBug

comment:2 by Gabaie, 5 years ago

Easy pickings: set

comment:3 by Simon Charette, 5 years ago

Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

I guess we could adapt the code not to include any key if the count is zero in the second case.

comment:4 by Hasan Ramezani, 5 years ago

Owner: changed from nobody to Hasan Ramezani
Status: newassigned

comment:5 by Hasan Ramezani, 5 years ago

Has patch: set
Version 0, edited 5 years ago by Hasan Ramezani (next)

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 35a67b37:

Fixed #31474 -- Made QuerySet.delete() not return the number of deleted objects if it's zero.

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