Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#10151 closed (worksforme)

url tag causes TypeError: dict objects are unhashable

Reported by: pclerie Owned by: nobody
Component: Uncategorized Version: 1.0
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

I'm trying out the examples in Practical Django Projects. When using named views with the url tag I get a TypeError: dict objects are unhashable (see the traceback below). The interesting thing is that it only happens _once_, the first time through. On following passes no problem occurs. I have reproduced the same behaviour with django.core.urlresolvers.reverse.

It seems I can work around this by putting a call to reverse in a try...except block in an __init__.py. That forces the first error and then no more problems.

Thanks

Philippe

=================

Traceback follows:

Environment:

Request Method: GET
Request URL: http://denebola.logisys.ht:8000/blog/
Django Version: 1.0.2 final
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.flatpages',
 'coltrane',
 'tagging']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Template error:
In template /home/philippe/prj/django/templates/base.html, error at line 33
   Caught an exception while rendering: dict objects are unhashable
   23 : 

   24 : <div id="header">

   25 :   <div id="logo">

   26 :   </div>

   27 :   <h1>L'iconoclaste</h1>

   28 :   <h5>Élucubrations d'un étranger chez lui.</h5>

   29 : </div>

   30 : 

   31 : <div id="menu">

   32 :   <ul>

   33 :     <li><a href=" {% url coltrane_entry_archive_index %} ">Accueil</a>

   34 :     {% block menu %}

   35 :     {% endblock %}

   36 :   </ul>

   37 : </div>

   38 : 

   39 : <div id="main">

   40 :   <div id="leftcol">

   41 :     <div id="navigation">

   42 :       <h4>Navigation</h4>

   43 :       <ul>

Traceback:
File "/var/lib/python-support/python2.5/django/core/handlers/base.py" in get_response
  86.                 response = callback(request, *callback_args, **callback_kwargs)
File "/var/lib/python-support/python2.5/django/views/generic/date_based.py" in archive_index
  49.     return HttpResponse(t.render(c), mimetype=mimetype)
File "/var/lib/python-support/python2.5/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/var/lib/python-support/python2.5/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/var/lib/python-support/python2.5/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/var/lib/python-support/python2.5/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/var/lib/python-support/python2.5/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/var/lib/python-support/python2.5/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/var/lib/python-support/python2.5/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/var/lib/python-support/python2.5/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/var/lib/python-support/python2.5/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/var/lib/python-support/python2.5/django/template/__init__.py" in render
  768.                 bits.append(self.render_node(node, context))
File "/var/lib/python-support/python2.5/django/template/debug.py" in render_node
  81.             raise wrapped

Exception Type: TemplateSyntaxError at /blog/
Exception Value: Caught an exception while rendering: dict objects are unhashable

Original Traceback (most recent call last):
  File "/var/lib/python-support/python2.5/django/template/debug.py", line 71, in render_node
    result = node.render(context)
  File "/var/lib/python-support/python2.5/django/template/defaulttags.py", line 373, in render
    url = reverse(self.view_name, args=args, kwargs=kwargs)
  File "/var/lib/python-support/python2.5/django/core/urlresolvers.py", line 254, in reverse
    *args, **kwargs)))
  File "/var/lib/python-support/python2.5/django/core/urlresolvers.py", line 227, in reverse
    possibilities = self.reverse_dict.getlist(lookup_view)
  File "/var/lib/python-support/python2.5/django/core/urlresolvers.py", line 161, in _get_reverse_dict
    for name in pattern.reverse_dict:
  File "/var/lib/python-support/python2.5/django/core/urlresolvers.py", line 169, in _get_reverse_dict
    self._reverse_dict.appendlist(pattern.callback, (bits, p_pattern))
  File "/var/lib/python-support/python2.5/django/core/urlresolvers.py", line 130, in _get_callback
    self._callback = get_callable(self._callback_str)
  File "/var/lib/python-support/python2.5/django/utils/functional.py", line 128, in wrapper
    if mem_args in cache:
TypeError: dict objects are unhashable

Change History (3)

comment:1 by Malcolm Tredinnick, 16 years ago

There's no information here about how to repeat the problem. I cannot imagine how this would be happening, so please provide a short, step-by-step example of how to trigger it. If we can't repeat it, we cannot evaluate the issue.

comment:2 by Jacob, 16 years ago

Resolution: worksforme
Status: newclosed

comment:3 by zack, 15 years ago

This is caused by a programming error.

I just had the same error message (Django 1.1.1)

It was caused by an error in my url conf.

I had a line like :

    ('^huur/indoor/$', {},'huur_indoor'),

Which should have been like:

    ('^huur/indoor/$', 'xl.views.huur_indoor', {},'huur_indoor'),
Note: See TracTickets for help on using tickets.
Back to Top