Opened 7 years ago

Closed 7 years ago

Last modified 5 years ago

#12647 closed (fixed)

Django admin unique validation fails

Reported by: jtiai Owned by: Honza_Kral
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: UI/UX:


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


Traceback (most recent call last):
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/core/servers/", line 672, in __call__
    return self.application(environ, start_response)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/core/handlers/", line 241, in __call__
    response = self.get_response(request)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/core/handlers/", 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/", 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/", 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/", 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/", line 36, in __call__
    return self.decorator(self.func)(*args, **kwargs)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/utils/", line 86, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/utils/", line 36, in __call__
    return self.decorator(self.func)(*args, **kwargs)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/views/decorators/", 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/", line 190, in inner
    return view(request, *args, **kwargs)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/utils/", line 86, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/db/", line 295, in _commit_on_success
    res = func(*args, **kw)
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/contrib/admin/", line 882, in change_view
    if all_valid(formsets) and form_validated:
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/forms/", line 317, in all_valid
    if not formset.is_valid():
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/forms/", line 238, in is_valid
    if bool(self.errors[i]):
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/forms/", line 212, in _get_errors
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/forms/", line 254, in full_clean
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/forms/", line 432, in clean
  File "/home/KEYPRO/jtiai/src/django-workspaces/netreg/django-trunk/django/forms/", 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_Kral 7 years ago.

Download all attachments as: .zip

Change History (4)

Changed 7 years ago by Honza_Kral

comment:1 Changed 7 years ago by Honza_Kral

  • Has patch set
  • milestone set to 1.2
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to Honza_Kral
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 Changed 7 years ago by jkocherhans

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

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

comment:3 Changed 5 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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