Opened 3 years ago

Closed 3 years ago

#19838 closed Bug (fixed)

Deleting a protected fk relationships throws error 500 when deleting inlines

Reported by: rafadev Owned by: javimansilla
Component: contrib.admin Version: 1.4
Severity: Normal Keywords: sprints-django-ar
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Better explained with an example.

We have 3 models, Category, Subcategory and Item. Subcategory has a protected (on_delete=models.PROTECT) fk relationship to Category, and Item has a protected fk relationship to Subcategory.

When trying to delete a Category that has Subcategories, the Django admin displays a readable, understandable message explaining that the model instance has related models, so it can't be deleted. However, if the Subcategories are displayed as inlines in the Category admin, and one tries to delete a Subcategory that has related items, Django throws an uncatched error 500, instead of a human-readable message.

Change History (7)

comment:1 Changed 3 years ago by rafadev

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

It is clear in the documentation that models.PROTECT will raise an exception, however, it is nicely caught on the regular ModelAdmin, but not on inlines.

comment:2 Changed 3 years ago by carljm

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 3 years ago by javimansilla

  • Owner changed from nobody to javimansilla
  • Status changed from new to assigned

comment:4 Changed 3 years ago by javimansilla

  • Keywords sprints-django-ar added

comment:5 Changed 3 years ago by javimansilla

  • Has patch set

comment:7 Changed 3 years ago by Ramiro Morales <cramm0@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 3ea0c7d35ac461cb469170486683d10732eb534b:

Fixed #19838 -- Admin: Don't leak a 500 HTTP status when trying to delete protected FKs.

Thanks rafadev for the report and Javier Mansilla for the fix.

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