Opened 18 months ago

Last modified 3 weeks ago

#29087 assigned Bug

Impossible to delete pending new inline in admin when invalid (delete button missing)

Reported by: Owen Heisler Owned by: frnhr
Component: contrib.admin Version: 2.0
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: yes


When adding a new inline record in the Django Admin, it is impossible to delete the record if it has had a validation error. This is the most evident to the user if he/she accidentally attempts to use the wrong inline for some data. For example, if a ContactAdmin has both PhoneInline and EmailInline, the user may accidentally enter a phone number in an EmailInline record. When attempting to submit the changes, a validation error is raised. Seeing the problem, the user would now like to just delete the new record that is pending. However, at this point there is no Delete button. Thus the user is forced to either (a) reload the change page, discarding any other unrelated pending changes on the page; or (b) change the data to make it valid, click Save and continue editing, and then delete the offending record before finally saving the changes again.

Test code

Consider the following code, where the Django Admin provides access to a Groups page with a Persons inline.

from django.db import models

class Group(models.Model):
    name = models.CharField(max_length=30)

class Person(models.Model):
    group = models.ForeignKey(Group, on_delete=models.CASCADE)
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)

from django.contrib import admin
from .models import *

class PersonInline(admin.StackedInline):
    model = Person
    extra = 0

class GroupAdmin(admin.ModelAdmin):
    inlines = [PersonInline]

Steps to reproduce

  1. Go to the Group add page (for example, <http://localhost:8000/admin/myapp/group/add/>). Enter a Group name, add a Person with first_name and last_name, and click Save and continue editing.
  2. Change the Group name. Add a second Person for the group, but enter a first_name only. A delete button (X icon) is available to discard the pending record:
  3. Click SAVE. There will be a validation error, as expected, because last_name is not provided. However, the Delete button is missing:
  4. The user is now forced to either (a) fix the validation error or (b) reload the page, discarding all unrelated changes on the page. It is not possible for the user to fix the validation error by simply canceling/deleting the pending new record.

Change History (3)

comment:1 Changed 18 months ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:4 Changed 6 weeks ago by frnhr

Owner: set to frnhr
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top