django icon indicating copy to clipboard operation
django copied to clipboard

Swap `_rows_count` and `deleted` in `QuerySet.delete`.

Open expert-m opened this issue 2 years ago • 1 comments

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.

expert-m avatar May 18 '22 07:05 expert-m

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 ⛵️!

github-actions[bot] avatar May 18 '22 07:05 github-actions[bot]

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?

timgraham avatar Dec 18 '23 21:12 timgraham

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.

expert-m avatar Jan 01 '24 17:01 expert-m

@felixxm please take a look.

timgraham avatar Jan 01 '24 19:01 timgraham

@expert-m Thanks for this patch :+1: Welcome aboard :boat:

@felixxm please take a look.

Looks good, thanks :+1:

felixxm avatar Jan 02 '24 04:01 felixxm