Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#11415 closed (wontfix)

Django doesn't call delete() for relatively deleted objects.

Reported by: Loststylus Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

A simple example:

class Link(models.Model):

num = models.IntegerField('foo')

def delete(self):

super(Link, self).delete()
print('doing some cleanup after killing self')

class Something(models.Model):

link = models.ForeignField(Link)

Okay, now delete some "Links" from Admin site - delete() is called.
Try to delete some "Somethings" with relations - they are deleted and related "Links" are deleted, too, but delete() is not called for related objects.

Change History (3)

comment:1 Changed 7 years ago by Loststylus

Sorry for code mess

class Link(models.Model):
    num = models.IntegerField('foo')

    def delete(self):
        super(Link, self).delete()
        print('doing some cleanup after killing self')

class Something(models.Model):
    link = models.ForeignField(Link)

comment:2 Changed 7 years ago by Russell Keith-Magee

Resolution: wontfix
Status: newclosed

This is by design, and documented as such. If delete() is called on the cascade, you could end up with a flood of calls to delete() methods. To prevent this sort of flood, delete() is only invoked on a direct call to delete an object.

comment:3 Changed 7 years ago by Loststylus

So, how a developer supposed to do clean-up routines after deleting objects? It's wrong to iterate through related objects and call delete() on each of them from the delete() function.

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