Opened 17 years ago

Closed 16 years ago

Last modified 13 years ago

#7276 closed (fixed)

Inherited models are not fully deleted

Reported by: John Millikin Owned by: nobody
Component: Database layer (models, ORM) Version: dev
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

Description

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.id
1
>>> 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 17 years ago.
Updated model inheritance unit tests

Download all attachments as: .zip

Change History (6)

by John Millikin, 17 years ago

Updated model inheritance unit tests

comment:1 by George Vilches, 17 years ago

Keywords: qsrf-cleanup added

comment:2 by Jacob, 17 years ago

milestone: 1.0

comment:3 by Julien Phalip, 17 years ago

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):

parent.delete()

comment:4 by Malcolm Tredinnick, 16 years ago

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 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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