Django

Code

Ticket #7276 (closed: fixed)

Opened 4 months ago

Last modified 2 months ago

Inherited models are not fully deleted

Reported by: jmillikin Assigned to: nobody
Milestone: 1.0 Component: Database wrapper
Version: SVN Keywords: qsrf-cleanup
Cc: Triage Stage: Design decision needed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

delete-parent-objects-test.diff (0.7 kB) - added by jmillikin on 05/20/08 16:42:05.
Updated model inheritance unit tests

Change History

05/20/08 16:42:05 changed by jmillikin

  • attachment delete-parent-objects-test.diff added.

Updated model inheritance unit tests

06/10/08 09:42:08 changed by gav

  • keywords set to qsrf-cleanup.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

06/16/08 12:10:45 changed by jacob

  • milestone set to 1.0.

06/16/08 17:23:42 changed by julien

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

parent.delete()

06/29/08 04:41:36 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #7276 (Inherited models are not fully deleted)




Change Properties
Action