Opened 17 years ago

Closed 17 years ago

#6468 closed (duplicate)

nested ForNode iteration over non-sequence attributed to parent

Reported by: Joshua Tacoma <joshua@…> Owned by: nobody
Component: Template system Version: dev
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

When a ForNode contains a ForNode over a non-sequence, the resulting TemplateSyntaxError refers incorrectly to the first ForNode.source.

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
from django.template import Context, Template, TemplateSyntaxError
source = '''{% for item1 in list1 %}
{% for item2 in list2 %}
{% endfor %}
{% endfor %}'''
try:
    Template(source).render(Context(dict(list1=[1], list2=2)))
except TemplateSyntaxError, e:
    print source[e.source[1][0] : e.source[1][1]]
    print e.exc_info[1]

Ought to produce this output:

{% for item2 in list2 %}
iteration over non-sequence

But instead produces this:

{% for item1 in list1 %}
iteration over non-sequence

...which is quite misleading. May be related to #4565?

I'll be studying the flow of template/debug.py and template/defaulttags.py but this is my first effort to fix a bug in Django so it's more of a learning exercise. If you already know how to solve this, well, don't wait for me!

Change History (2)

comment:1 by Jim <jim-django@…>, 17 years ago

related to #5831 ?

in reply to:  1 comment:2 by Gary Wilson, 17 years ago

Resolution: duplicate
Status: newclosed

Replying to Jim <jim-django@dsdd.org>:

related to #5831 ?

Yes, I'd say it's a dup.

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