1. Matthew Schinckel
  2. django-jsonfield
  3. Issues
Issue #15 new

Exception Value: unhashable type: 'dict'

Vladislav Polukhin
created an issue
  • Django==1.4.1
  • django-jsonfield==0.8.11

My models.py:

{{{

!python

class Category(MPTTModel): parent = TreeForeignKey('self', null=True, blank=True, related_name='children') relations = TreeManyToManyField('self', through='CategoryRelation', symmetrical=False, blank=True, related_name='category')

class CategoryRelation(models.Model): from_category = TreeForeignKey(Category, related_name='from_category') to_category = TreeForeignKey(Category, related_name='to_category') filters = JSONField() }}}

My admin.py:

{{{

!python

class CategoryLinkInline(admin.StackedInline): model = Category.relations.through fk_name = 'from_category' fields = ('to_category', 'filters') extra = 0

class CategoryAdmin(MPTTModelAdmin): model = Category inlines = [CategoryLinkInline] }}}

After save in django admin I get error:

{{{

!python

Traceback: File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 111. response = callback(request, callback_args, callback_kwargs) File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper 366. return self.admin_site.admin_view(view)(*args, kwargs) File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 91. response = view_func(request, args, kwargs) File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 89. response = view_func(request, *args, kwargs) File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner 196. return view(request, args, kwargs) File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper 25. return bound_func(*args, kwargs) File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view 91. response = view_func(request, args, kwargs) File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func 21. return func(self, *args2, kwargs2) File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/db/transaction.py" in inner 209. return func(args, *kwargs) File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/contrib/admin/options.py" in change_view 1053. if all_valid(formsets) and form_validated: File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/forms/formsets.py" in all_valid 372. if not formset.is_valid(): File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/forms/formsets.py" in is_valid 269. err = self.errors File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/forms/formsets.py" in _get_errors 247. self.full_clean() File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/forms/formsets.py" in full_clean 293. self.clean() File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/forms/models.py" in clean 500. self.validate_unique() File "/home/user/.virtualenvs/project/lib/python2.7/site-packages/django/forms/models.py" in validate_unique 527. if row_data in seen_data:

Exception Type: TypeError at /admin/base/projectcategory/2157/ Exception Value: unhashable type: 'dict'

}}}

Comments (4)

  1. Matthew Schinckel repo owner

    I haven't had a chance to try to reproduce this (and haven't seen anything like it elsewhere).

    It looks like a dict is being used as a key for another dict, which clearly won't work.

  2. Log in to comment