Opened 17 years ago

Closed 12 years ago

#6818 closed Bug (duplicate)

Generic Relations, doesn't seem to delete all related objects.

Reported by: Niklas Collin Owned by: nobody
Component: contrib.contenttypes Version: dev
Severity: Normal Keywords: GenericForeignRelation, deletion
Cc: niklas@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Django doesn't seem to delete all related objects.
Below: an owner has property has 2 resource.
Deleting the owner will delete the property but not the resources

class Property(models.Model):
    owner = generic.GenericForeignKey()        
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()

class Resource(models.Model):
    property = models.ForeignKey(Property, edit_inline=models.STACKED, num_in_admin=10) 
    language_id = models.IntegerField(default=1, core=True)
    class Meta:
        unique_together = (("property", "language_id"),)   

class AnExampleOwner(models.Model):
    properties = generic.GenericRelation(Property) 

An example from the interpreter

In [2]: AnExampleOwner.objects.all().count()
Out[2]: 0L

In [3]: Property.objects.all().count()
Out[3]: 0L

In [4]: Resource.objects.all().count()
Out[4]: 0L

In [5]: o=AnExampleOwner()

In [6]: o.save()

In [7]: p=Property(owner = o)

In [8]: p.save()

In [9]: r=Resource(property=p, language_id = 1)

In [10]: r.save()

In [11]: r=Resource(property=p, language_id = 2)

In [12]: r.save()

In [13]: AnExampleOwner.objects.all().count()
Out[13]: 1L

In [14]: Property.objects.all().count()
Out[14]: 1L

In [15]: Resource.objects.all().count()
Out[15]: 2L

In [16]: o.delete()

In [17]: AnExampleOwner.objects.all().count()
Out[17]: 0L

In [18]: Property.objects.all().count()
Out[18]: 0L

In [19]: Resource.objects.all().count()
Out[19]: 2L

Attachments (1)

6818-failing-tests-against-8818.diff (1.9 KB ) - added by Honza Král 16 years ago.
tests that fail for the current SVN version

Download all attachments as: .zip

Change History (8)

comment:1 by Niklas Collin, 17 years ago

Cc: niklas@… added

Further results: Deleting a property directly will delete the resources connected to it (i.e. that works correctly)

comment:2 by Marc Fargas, 16 years ago

Summary: Django doesn't seem to delete all related objects.Generic Relations, doesn't seem to delete all related objects.
Triage Stage: UnreviewedAccepted

by Honza Král, 16 years ago

tests that fail for the current SVN version

comment:3 by Julien Phalip, 14 years ago

Severity: Normal
Type: Bug

comment:4 by anonymous, 14 years ago

Component: Database layer (models, ORM)contrib.contenttypes

comment:5 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:6 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:7 by Ramiro Morales, 12 years ago

Resolution: duplicate
Status: newclosed

Duplicate of (newer, already fixed) #12953.

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