Opened 6 years ago

Closed 6 years ago

#29740 closed Bug (duplicate)

Wrong lines shown on ValueError when rendering template with a bad for-loop

Reported by: Vasili Korol Owned by: nobody
Component: Template system Version: 1.11
Severity: Normal Keywords: template, valueerror, reporting
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Consider the following setup:

  1. There is a top level template (main.html):
    <!DOCTYPE html>
    
    {% load staticfiles %}
    {% load compress %}
    {% load cms_tags sekizai_tags %}
    {% load solo_tags %}
    {% load lists %}
    {% load userextras %}
    
    {% get_solo 'maintenance.SiteConfiguration' as site_config %}
    
    ... Long template body ....
    
    {% block content %}
    {% endblock %}
    ...
    
  1. A child template "taskclasses.html" that extends "main.html":
    {% extends ajax|yesno:"ajax.html,main.html" %}
                                                  
    {% load staticfiles %}                        
    {% load compress %}                           
    {% load userextras %}                         
    ...
                                                  
    {% block content %}                           
        ...
        {% for group, task_classes in task_classes_grouped %}
            ....
        {% endfor %}
        ...
    {% endblock %}
    

In my case, task_classes_grouped was a dict, so the "for" loop in "taskclasses.html" is invalid. This expectedly results in a ValueError, but the exception is reported wrongly:

ValueError at /projects/1/taskclasses
Need 2 values to unpack in for loop; got 1. 

Request Method:	GET
Request URL:	http://devel:20062/projects/1/taskclasses
Django Version:	1.11.15
Exception Type:	ValueError
Exception Value:	
Need 2 values to unpack in for loop; got 1. 
Exception Location:	/usr/local/lib/python3.4/dist-packages/django/template/defaulttags.py in render, line 207
Python Executable:	/usr/local/bin/uwsgi
Python Version:	3.4.3
Python Path:	
['/www/deploy/lib',
 '/data/programs/openbabel/lib/python3.4/site-packages/',
 '/www/deploy/apps/',
 '.',
 '',
 '/usr/lib/python3.4',
 '/usr/lib/python3.4/plat-x86_64-linux-gnu',
 '/usr/lib/python3.4/lib-dynload',
 '/usr/local/lib/python3.4/dist-packages',
 '/usr/lib/python3/dist-packages',
 '/www/deploy']
Server time:	Thu, 6 Sep 2018 11:52:03 +0000

...
Error during template rendering
In template /www/deploy/viking/templates/main.html, error at line 0

Need 2 values to unpack in for loop; got 1.
1	<!DOCTYPE html>
2	
3	{% load staticfiles %}
4	{% load compress %}
5	{% load cms_tags sekizai_tags %}
6	{% load solo_tags %}
7	{% load lists %}
8	{% load userextras %}
9	
10	{% get_solo 'maintenance.SiteConfiguration' as site_config %}

This does not include the line that actually failed, and the template reference is wrong (parent template instead of the child).

Change History (1)

comment:1 by Simon Charette, 6 years ago

Resolution: duplicate
Status: newclosed

Looks like a duplicate of #28935.

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