Opened 6 years ago
Closed 6 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 , 6 years ago
| Type: | Uncategorized → Bug | 
|---|
comment:2 by , 6 years ago
| Easy pickings: | set | 
|---|
comment:3 by , 6 years ago
| Triage Stage: | Unreviewed → Accepted | 
|---|---|
| Type: | Bug → Cleanup/optimization | 
comment:4 by , 6 years ago
| Owner: | changed from to | 
|---|---|
| Status: | new → assigned | 
I guess we could adapt the code not to include any key if the count is zero in the second case.