Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 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:

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_Kral 4 years ago.

Download all attachments as: .zip

Change History (4)

Changed 4 years ago by Honza_Kral

comment:1 Changed 4 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 4 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 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.