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)
Change History (8)
comment:1 by , 17 years ago
Cc: | added |
---|
comment:2 by , 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: | Unreviewed → Accepted |
by , 16 years ago
Attachment: | 6818-failing-tests-against-8818.diff added |
---|
tests that fail for the current SVN version
comment:3 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:4 by , 14 years ago
Component: | Database layer (models, ORM) → contrib.contenttypes |
---|
comment:7 by , 12 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Duplicate of (newer, already fixed) #12953.
Note:
See TracTickets
for help on using tickets.
Further results: Deleting a property directly will delete the resources connected to it (i.e. that works correctly)