Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#7276 closed (fixed)

Inherited models are not fully deleted

Reported by: John Millikin Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: qsrf-cleanup
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


With the following models:

class Place (models.Model):
	name = models.CharField (max_length = 255, unique = True)
class Store (Place):
	manager = models.CharField (max_length = 255)

This is the behavior of delete(), which is unexpected. Attempting to delete objects with inherited relationships leaves a trail of half-built objects behind. The call to store.delete() should also remove the associated Place.

>>> store = Store.objects.create (name = "My Store", manager = "Frank")
>>> store.delete ()
>>> Place.objects.get (id = 1).name
'My Store'
>>> Store.objects.create (name = "My Store", manager = "Bob")
Traceback (most recent call last):
IntegrityError: (1062, "Duplicate entry 'My Store' for key 2")

Attachments (1)

delete-parent-objects-test.diff (731 bytes) - added by John Millikin 10 years ago.
Updated model inheritance unit tests

Download all attachments as: .zip

Change History (6)

Changed 10 years ago by John Millikin

Updated model inheritance unit tests

comment:1 Changed 10 years ago by George Vilches

Keywords: qsrf-cleanup added

comment:2 Changed 10 years ago by Jacob

milestone: 1.0

comment:3 Changed 10 years ago by Julien Phalip

Triage Stage: UnreviewedDesign decision needed

There needs to be a design decision: do we want or not to delete the parent *automatically* when the child is deleted?

It is still possible to do it manually with something like:

class Store (Place):

parent = models.OneToOneField(Place, parent_link=True)
manager = models.CharField (max_length = 255)

def delete(self):


comment:4 Changed 10 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [7784]) Fixed #7276 -- Delete multi-table objects correctly.

When model inheritance is used, the parent objects should be deleted as part of
the delete() call on the child.

comment:5 Changed 7 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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