#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 , 3 years ago
Summary: | Django ORM bug → Django ORM bug: overloading delete() method of models |
---|
follow-up: 3 comment:2 by , 3 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:3 by , 3 years ago
Replying to Mariusz Felisiak:
Model.delete()
is not called when deleting objects in bulk usingQuerySet.delete()
, see Overriding predefined model methods for more details.
Thank you a lot.
Model.delete()
is not called when deleting objects in bulk usingQuerySet.delete()
, see Overriding predefined model methods for more details.