#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)
Change History (6)
by , 17 years ago
Attachment: | delete-parent-objects-test.diff added |
---|
comment:1 by , 17 years ago
Keywords: | qsrf-cleanup added |
---|
comment:2 by , 17 years ago
milestone: | → 1.0 |
---|
comment:3 by , 17 years ago
Triage Stage: | Unreviewed → 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):
parent.delete()
comment:4 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Updated model inheritance unit tests