Opened 15 years ago

Closed 15 years ago

Last modified 15 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: no UI/UX: no

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 by Loststylus, 15 years ago

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 by Russell Keith-Magee, 15 years ago

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 by Loststylus, 15 years ago

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