-
-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
delete() method don't returns number of affected rows #541
Comments
I'm running into the same issue when adding type annotations: mypy warns that What would be the correct returned value: The latter might be tricky, as it would have to take into account how many objects already had |
I don't know whether returning "nothing was deleted" is the best option, but at least the returned value now has the correct type. jazzband#541
Note that |
I don't know whether returning "nothing was deleted" is the best option, but at least the returned value now has the correct type. jazzband#541
I don't know whether returning "nothing was deleted" is the best option, but at least the returned value now has the correct type. jazzband#541
I think soft deletion is supposed to mimic normal deletion. So suppose you do a soft delete of something and show the user that N records have been deleted. To him, those are the real N records that have been deleted. The fact that they are soft deleted is more your internal implementation. |
I don't know whether returning "nothing was deleted" is the best option, but at least the returned value now has the correct type. jazzband#541
I don't know whether returning "nothing was deleted" is the best option, but at least the returned value now has the correct type. jazzband#541
I don't know whether returning "nothing was deleted" is the best option, but at least the returned value now has the correct type. jazzband#541
I don't know whether returning "nothing was deleted" is the best option, but at least the returned value now has the correct type. jazzband#541
I don't know whether returning "nothing was deleted" is the best option, but at least the returned value now has the correct type. jazzband#541
I don't know whether returning "nothing was deleted" is the best option, but at least the returned value now has the correct type. jazzband#541
I don't know whether returning "nothing was deleted" is the best option, but at least the returned value now has the correct type. jazzband#541
I wrote:
Mogost wrote:
I agree that would be the most intuitive behavior from the user's perspective. Maybe a pragmatic solution would be to return the number of objects updated by soft-delete, whether they were previously soft-deleted or not. In practice, it's likely that objects that were already soft-deleted would be not be included in a query to soft-delete other records, as |
I believe we can easily mimic the original API ? class SoftDeletableQuerySetMixin:
"""
QuerySet for SoftDeletableModel. Instead of removing instance sets
its ``is_removed`` field to True.
"""
def delete(self):
"""
Soft delete objects from queryset (set their ``is_removed``
field to True)
"""
number_of_deleted_objects = self.update(is_removed=True)
return number_of_deleted_objects, {self.model._meta.label: number_of_deleted_objects} This is valid because
What you folks think ? |
Closing since #622 was merged and part of the recent 5.0 release. |
Problem
As documentation says: https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.delete
Instead overridden delete() method return None
Tips: since you are performing an update and not a delete, please consider using bulk_update.
Environment
The text was updated successfully, but these errors were encountered: