Opened 17 years ago

Closed 17 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: dev
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

Description

Given the following:

class Poll(models.Model):
    question = models.CharField(maxlength=255, unique=True)
    pub_date = models.DateTimeField('Publish date', default=datetime.now(), help_text='The date when the poll goes live. Defaults to now.')
    close_date = models.DateTimeField(default=datetime.now()+timedelta(7), 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/base.py", line 77, in get_response
    response = callback(request, *callback_args, **callback_kwargs)

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

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

  File "/home/3781lanru0j/lib/python2.4/django/contrib/admin/views/main.py", line 261, in add_stage
    new_object = manipulator.save(new_data)

  File "/home/3781lanru0j/lib/python2.4/django/db/models/manipulators.py", line 202, in save
    new_rel_obj.save()

  File "/home/3781lanru0j/lib/python2.4/django/db/models/base.py", 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/cursors.py", 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/connections.py", line 35, in defaulterrorhandler
    raise errorclass, errorvalue

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

<ModPythonRequest
path:/admin/polls/poll/add/,
GET:<MultiValueDict: {u'_popup': [u'1']}>,
POST:<MultiValueDict: {u'choice.1.id': [u''], u'choice.1.choice': [u'It makes me wish I had gone to U of T'], u'choice.4.id': [u''], u'choice.0.choice': [u"I don't really mind"], u'close_date_date': [u'2007-09-10'], u'choice.3.id': [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'choice.0.id': [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'choice.2.id': [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 by Philippe Raoult, 17 years ago

Component: UncategorizedAdmin interface

comment:2 by Jacob, 17 years ago

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