Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#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

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 Tim Graham, 9 years ago

Component: Uncategorizedcontrib.admin
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:2 by Sergey Fedoseev, 9 years ago

Owner: changed from nobody to Sergey Fedoseev
Status: newassigned

comment:3 by Sergey Fedoseev, 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)

PR -- https://github.com/django/django/pull/5796

comment:4 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 8ab58b80:

Fixed #25883 -- Fixed admin deletion page summary counts for related objects.

comment:5 by Tim Graham <timograham@…>, 9 years ago

In 515f149e:

[1.9.x] Fixed #25883 -- Fixed admin deletion page summary counts for related objects.

Backport of 8ab58b80529c5206654c1042a4ddcf2da364f8ec from master

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