Opened 8 years ago

Closed 7 years ago

Last modified 4 years ago

#7276 closed (fixed)

Inherited models are not fully deleted

Reported by: jmillikin 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: UI/UX:


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 jmillikin 8 years ago.
Updated model inheritance unit tests

Download all attachments as: .zip

Change History (6)

Changed 8 years ago by jmillikin

Updated model inheritance unit tests

comment:1 Changed 7 years ago by gav

  • Keywords qsrf-cleanup added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 7 years ago by jacob

  • milestone set to 1.0

comment:3 Changed 7 years ago by julien

  • Triage Stage changed from Unreviewed to Design 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 7 years ago by mtredinnick

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

(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 4 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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