django
django copied to clipboard
Swap `_rows_count` and `deleted` in `QuerySet.delete`.
The doc says:
The delete method, conveniently, is named [delete()](https://docs.djangoproject.com/en/4.0/ref/models/instances/#django.db.models.Model.delete). This method immediately deletes the object and returns the number of objects deleted and a dictionary with the number of deletions per object type. Example:
>>> e.delete()
(1, {'blog.Entry': 1})
And if we check Collector.delete
we will see:
return sum(deleted_counter.values()), dict(deleted_counter)
But in QuerySet.delete
I see:
deleted, _rows_count = collector.delete()
# Clear the result cache, in case this QuerySet gets reused.
self._result_cache = None
return deleted, _rows_count
So, we need to swap _rows_count
and deleted
. It won't change the logic, but will fix the code from misunderstanding.
Hello @expert-m! Thank you for your contribution 💪
As it's your first contribution be sure to check out the patch review checklist.
If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!
If you have any design or process questions then you can ask in the Django forum.
Welcome aboard ⛵️!
Thanks for raising this. I think this is intentional as is, but I agree the names aren't very good. How about num_deleted, num_deleted_per_model
?
Thanks for raising this. I think this is intentional as is, but I agree the names aren't very good. How about
num_deleted, num_deleted_per_model
?
Thank you for checking. I have updated the names.
@felixxm please take a look.
@expert-m Thanks for this patch :+1: Welcome aboard :boat:
@felixxm please take a look.
Looks good, thanks :+1: