Code

Opened 5 years ago

Closed 5 years ago

Last modified 5 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.

Attachments (0)

Change History (3)

comment:1 Changed 5 years ago by Loststylus

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 5 years ago by russellm

  • Resolution set to wontfix
  • Status changed from new to closed

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 5 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.