Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#12647 closed (fixed)

Django admin unique validation fails

Reported by: Jani Tiainen Owned by: Honza Král
Component: contrib.admin Version: 1.2-alpha
Severity: 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

If Model Meta has unique_together set as sequence admin view fails. If unique_together is tuple admin works as expected.

Traceback:

Traceback (most recent call last):
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/core/servers/basehttp.py", line 672, in __call__
    return self.application(environ, start_response)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/core/handlers/base.py", line 143, in get_response
    return self.handle_uncaught_exception(request, resolver, exc_info)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/core/handlers/base.py", line 167, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/core/handlers/base.py", line 101, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/contrib/admin/options.py", line 238, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/utils/decorators.py", line 36, in __call__
    return self.decorator(self.func)(*args, **kwargs)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/utils/decorators.py", line 86, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/utils/decorators.py", line 36, in __call__
    return self.decorator(self.func)(*args, **kwargs)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/views/decorators/cache.py", line 70, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/contrib/admin/sites.py", line 190, in inner
    return view(request, *args, **kwargs)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/utils/decorators.py", line 86, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/db/transaction.py", line 295, in _commit_on_success
    res = func(*args, **kw)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/contrib/admin/options.py", line 882, in change_view
    if all_valid(formsets) and form_validated:
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/forms/formsets.py", line 317, in all_valid
    if not formset.is_valid():
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/forms/formsets.py", line 238, in is_valid
    if bool(self.errors[i]):
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/forms/formsets.py", line 212, in _get_errors
    self.full_clean()
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/forms/formsets.py", line 254, in full_clean
    self.clean()
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/forms/models.py", line 432, in clean
    self.validate_unique()
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/forms/models.py", line 443, in validate_unique
    all_unique_checks = all_unique_checks.union(set(unique_checks))
TypeError: unhashable type: 'list'

>>> unique_checks
[['ssp_category', 'email_type']]

Attachments (1)

12647.dif (1.6 KB ) - added by Honza Král 14 years ago.

Download all attachments as: .zip

Change History (4)

by Honza Král, 14 years ago

Attachment: 12647.dif added

comment:1 by Honza Král, 14 years ago

Has patch: set
milestone: 1.2
Owner: changed from nobody to Honza Král
Triage Stage: UnreviewedAccepted

Attached a patch that takes care of this. it's a simple fix and performance-wise it was better to always convert to tuple then to check (timeit claims so).

comment:2 by jkocherhans, 14 years ago

Resolution: fixed
Status: newclosed

(In [12403]) Fixed #12647. Allow unique_together checks be specified as lists as well as tuples. Thanks, Honza Král.

comment:3 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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