malthe/chameleon — Issue #79: tal:repeat over a dict produces weird error message when using bad syntax
Author: pitchum
Created: 2011-12-15 12:45:18+00:00
State: open

I used to iterate over dict entries like the following with chameleon 1.2.x without getting any error:

Upgrading to chameleon 2.7, such templates now fail and here is the stacktrace:

Traceback (most recent call last):
File "/usr/lib/python3.2/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python3.2/dist-packages/pyramid-1.3a2-py3.2.egg/pyramid/router.py", line 187, in __call__
response = self.handle_request(request)
File "/usr/local/lib/python3.2/dist-packages/pyramid_debugtoolbar-0.9.7-py3.2.egg/pyramid_debugtoolbar/toolbar.py", line 103, in toolbar_tween
return handler(request)
File "/usr/local/lib/python3.2/dist-packages/pyramid-1.3a2-py3.2.egg/pyramid/tweens.py", line 20, in excview_tween
response = handler(request)
File "/usr/local/lib/python3.2/dist-packages/pyramid_tm-0.3-py3.2.egg/pyramid_tm/__init__.py", line 61, in tm_tween
response = handler(request)
File "/usr/local/lib/python3.2/dist-packages/pyramid-1.3a2-py3.2.egg/pyramid/router.py", line 164, in handle_request
response = view_callable(context, request)
File "/usr/local/lib/python3.2/dist-packages/pyramid-1.3a2-py3.2.egg/pyramid/config/views.py", line 335, in rendered_view
context)
File "/usr/local/lib/python3.2/dist-packages/pyramid-1.3a2-py3.2.egg/pyramid/renderers.py", line 395, in render_view
return self.render_to_response(response, system, request=request)
File "/usr/local/lib/python3.2/dist-packages/pyramid-1.3a2-py3.2.egg/pyramid/renderers.py", line 424, in render_to_response
result = self.render(value, system_values, request=request)
File "/usr/local/lib/python3.2/dist-packages/pyramid-1.3a2-py3.2.egg/pyramid/renderers.py", line 420, in render
result = renderer(value, system_values)
File "/usr/local/lib/python3.2/dist-packages/pyramid-1.3a2-py3.2.egg/pyramid/chameleon_zpt.py", line 51, in __call__
result = self.template(**system)
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/template.py", line 128, in __call__
return self.render(**kwargs)
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/zpt/template.py", line 247, in render
return super(PageTemplate, self).render(**vars)
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/template.py", line 172, in render
self.cook_check()
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/template.py", line 291, in cook_check
self.cook(body)
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/template.py", line 150, in cook
program = self._cook(body, digest, names)
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/template.py", line 217, in _cook
source = self._make(body, builtins)
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/template.py", line 248, in _make
program = self.parse(body)
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/zpt/template.py", line 191, in parse
implicit_i18n_attributes=self.implicit_i18n_attributes,
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/zpt/program.py", line 136, in __init__
super(MacroProgram, self).__init__(*args, **kwargs)
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/program.py", line 32, in __init__
node = self.visit(kind, args)
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/program.pyx, line 38, in visit
return visitor(*args)
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/zpt/program.py", line 507, in visit_element
body.append(self.visit(*child))
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/program.py", line 38, in visit
return visitor(*args)
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/zpt/program.py", line 507, in visit_element
body.append(self.visit(*child))
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/program.py", line 38, in visit
return visitor(*args)
File "/usr/local/lib/python3.2/dist-packages/Chameleon-2.7.0-py3.2.egg/chameleon/zpt/program.py", line 383, in visit_element
assert len(defines) == 1
TypeError: object of type 'NoneType' has no len()

I finally found out that the right syntax was `tal:repeat="(key,value) mydict.items()"` but I think the error message should be more excplit.
For example, something saying: "Invalid syntax for repeat: 'key,value mydict.items()'".