#25883 closed Bug (fixed)
Admin Delete Page Incorrectly Counts Related Objects
Reported by: | James Pulec | Owned by: | Sergey Fedoseev |
---|---|---|---|
Component: | contrib.admin | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Pull Requests: | |||
Description ¶
In the case where we're deleting an object (A) that has dependent foreign object (B) that points to it, and a different dependent foreign object (C) that also has B as a dependent foreign object, the admin will incorrectly double count this object. As an example:
class Spam(models.Model): pass class Egg(models.Model): spam = ForeignKey(Spam) class Shrubbery(models.Model): spam = ForeignKey(Spam) egg = ForeignKey(Egg) spam = Spam.objects.create() egg = Egg.objects.create(spam=spam) shrubbery = Shrubbery.objects.create(spam=spam, egg=egg)
If we issue a delete on an instance of Spam in this case, the admin will state that we are deleting 2 instances of Shrubbery, even though we are really only deleting 1 instance of Shrubbery that is attached both directly to the instance of Spam, and to the instance of Egg that is a dependent object of spam.
Change History (5)
comment:1 by , 9 years ago
Component: | Uncategorized → contrib.admin |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 9 years ago
Has patch: | set |
---|
Minimal example to reproduce:
class Shrubbery(models.Model): pass class KnightWhoSayNi(models.Model): shrubbery = ForeignKey(Shrubbery, related_name='+') another_shrubbery = ForeignKey(Shrubbery, related_name='+') shrubbery = Shrubbery.objects.create() KnightWhoSayNi.objects.create(shrubbery=shrubbery, another_shrubbery=shrubbery)
Reproduced at 0f2c2c104b51a226525d7e7baa65ea1fd27e994f. The original feature was added in 302145328560ded44bcfded8a67a1e7df08b411b.