Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#33500 closed Bug (invalid)

Django ORM bug: overloading delete() method of models

Reported by: Bobosher Owned by: nobody
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have overloaded delete() method of my model to enable soft deletion so that delete() method just sets is_deleted field to be true and calls build-in save() method.
It's working fine against individual model objects:

my_object = MyModel.objects.get(id=1)
my_object.delete() # Works fine, the object isn't actually deleted.

But when I called delete() method directly for a queryset, it just hard-deleted those objects included in the queryset:

some_objects = MyModel.objects.filter(id__lte=10)
some_objects.delete() # Those objects are actually deleted from the database.

Change History (3)

comment:1 by Bobosher, 3 years ago

Summary: Django ORM bugDjango ORM bug: overloading delete() method of models

comment:2 by Mariusz Felisiak, 3 years ago

Resolution: invalid
Status: newclosed

Model.delete() is not called when deleting objects in bulk using QuerySet.delete(), see Overriding predefined model methods for more details.

in reply to:  2 comment:3 by Bobosher, 3 years ago

Replying to Mariusz Felisiak:

Model.delete() is not called when deleting objects in bulk using QuerySet.delete(), see Overriding predefined model methods for more details.

Thank you a lot.

Note: See TracTickets for help on using tickets.
Back to Top