Opened 11 years ago

Closed 11 years ago

#5332 closed (wontfix)

Admin doesn't handle unique key conflicts on inline models cleanly

Reported by: Wesley Fok <portland@…> Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Given the following:

class Poll(models.Model):
    question = models.CharField(maxlength=255, unique=True)
    pub_date = models.DateTimeField('Publish date',, help_text='The date when the poll goes live. Defaults to now.')
    close_date = models.DateTimeField(, help_text='The date when the poll closes. Defaults to a week from now.')

    (stuff omitted)

class Choice(models.Model):
    choice = models.CharField(maxlength=255, unique=True, core=True)
    poll = models.ForeignKey(Poll, edit_inline=True, min_num_in_admin=2, num_in_admin=5, num_extra_on_change=3)

Attempting to add a Choice with the same choice text as a previously added Choice object, either in the same Poll or in a separate Poll, should give you a nice message in the admin interface saying an object with that choice text already exists. Instead, it throws a 500 error:

Traceback (most recent call last):

  File "/home/3781lanru0j/lib/python2.4/django/core/handlers/", line 77, in get_response
    response = callback(request, *callback_args, **callback_kwargs)

  File "/home/3781lanru0j/lib/python2.4/django/contrib/admin/views/", line 55, in _checklogin
    return view_func(request, *args, **kwargs)

  File "/home/3781lanru0j/lib/python2.4/django/views/decorators/", line 39, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)

  File "/home/3781lanru0j/lib/python2.4/django/contrib/admin/views/", line 261, in add_stage
    new_object =

  File "/home/3781lanru0j/lib/python2.4/django/db/models/", line 202, in save

  File "/home/3781lanru0j/lib/python2.4/django/db/models/", line 249, in save
    ','.join(placeholders)), db_values)

  File "/usr/local/lib/python2.5/site-packages/MySQL_python-1.2.2-py2.5-linux-i686.egg/MySQLdb/", line 166, in execute
    self.errorhandler(self, exc, value)

  File "/usr/local/lib/python2.5/site-packages/MySQL_python-1.2.2-py2.5-linux-i686.egg/MySQLdb/", line 35, in defaulterrorhandler
    raise errorclass, errorvalue

IntegrityError: (1062, "Duplicate entry 'I don't really mind' for key 2")

GET:<MultiValueDict: {u'_popup': [u'1']}>,
POST:<MultiValueDict: {u'': [u''], u'choice.1.choice': [u'It makes me wish I had gone to U of T'], u'': [u''], u'choice.0.choice': [u"I don't really mind"], u'close_date_date': [u'2007-09-10'], u'': [u''], u'choice.2.choice': [u"It's annoying, but the end result justifies it"], u'question': [u'What do you think of construction on campus?'], u'pub_date_time': [u'18:40:47'], u'': [u''], u'choice.3.choice': [u"It's ruining my university career"], u'_popup': [u'1'], u'close_date_time': [u'18:40:47'], u'choice.4.choice': [u"What construction? I'm too busy signing up for last-minute politics seminars"], u'': [u''], u'csrfmiddlewaretoken': [u'7c67d4c706c35c1cf2d7e67def5a1541'], u'pub_date_date': [u'2007-09-03']}>,


I know the current admin interface i being phased out, so this is unlikely to be fixed, but I figured it was worth mentioning in case the newforms admin has the same problem.

Change History (2)

comment:1 Changed 11 years ago by Philippe Raoult

Component: UncategorizedAdmin interface

comment:2 Changed 11 years ago by Jacob

Resolution: wontfix
Status: newclosed

We won't fix this on the old admin; someone should check if this problem persists on newforms-admin and open a new ticket if so.

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