[Django] #31474: QuerySet.Delete - inconsistent result when zero objects deleted

29 views
Skip to first unread message

Django

unread,
Apr 17, 2020, 7:12:22 AM4/17/20
to django-...@googlegroups.com
#31474: QuerySet.Delete - inconsistent result when zero objects deleted
-------------------------------------+-------------------------------------
Reporter: Adi | Owner: nobody
Gabaie |
Type: | Status: new
Uncategorized |
Component: Database | Version: 2.2
layer (models, ORM) | Keywords: querySet Delete
Severity: Normal | counter
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/31474>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 17, 2020, 7:13:37 AM4/17/20
to django-...@googlegroups.com
#31474: QuerySet.Delete - inconsistent result when zero objects deleted
-------------------------------------+-------------------------------------
Reporter: Adi Gabaie | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: querySet Delete | Triage Stage:
counter | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Adi Gabaie):

* type: Uncategorized => Bug


--
Ticket URL: <https://code.djangoproject.com/ticket/31474#comment:1>

Django

unread,
Apr 17, 2020, 8:06:35 AM4/17/20
to django-...@googlegroups.com
#31474: QuerySet.Delete - inconsistent result when zero objects deleted
-------------------------------------+-------------------------------------
Reporter: Adi Gabaie | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: querySet Delete | Triage Stage:
counter | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Gabaie):

* easy: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31474#comment:2>

Django

unread,
Apr 17, 2020, 8:23:51 AM4/17/20
to django-...@googlegroups.com
#31474: QuerySet.Delete - inconsistent result when zero objects deleted
-------------------------------------+-------------------------------------
Reporter: Adi Gabaie | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: querySet Delete | Triage Stage: Accepted
counter |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/31474#comment:3>

Django

unread,
Apr 17, 2020, 10:20:50 AM4/17/20
to django-...@googlegroups.com
#31474: QuerySet.Delete - inconsistent result when zero objects deleted
-------------------------------------+-------------------------------------
Reporter: Adi Gabaie | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned

Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: querySet Delete | Triage Stage: Accepted
counter |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* owner: nobody => Hasan Ramezani
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/31474#comment:4>

Django

unread,
Apr 18, 2020, 1:10:02 PM4/18/20
to django-...@googlegroups.com
#31474: QuerySet.Delete - inconsistent result when zero objects deleted
-------------------------------------+-------------------------------------
Reporter: Adi Gabaie | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: querySet Delete | Triage Stage: Accepted
counter |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31474#comment:5>

Django

unread,
Apr 20, 2020, 4:38:12 AM4/20/20
to django-...@googlegroups.com
#31474: QuerySet.Delete - inconsistent result when zero objects deleted
-------------------------------------+-------------------------------------
Reporter: Adi Gabaie | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: closed

Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: querySet Delete | Triage Stage: Accepted
counter |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"35a67b3731dab2b546b3ed4d7f2deff529465c34" 35a67b37]:
{{{
#!CommitTicketReference repository=""
revision="35a67b3731dab2b546b3ed4d7f2deff529465c34"
Fixed #31474 -- Made QuerySet.delete() not return the number of deleted
objects if it's zero.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31474#comment:6>

Reply all
Reply to author
Forward
0 new messages