Code

Opened 6 years ago

Closed 6 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: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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!

Attachments (0)

Change History (2)

comment:1 follow-up: Changed 6 years ago by Jim <jim-django@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

related to #5831 ?

comment:2 in reply to: ↑ 1 Changed 6 years ago by gwilson

  • Resolution set to duplicate
  • Status changed from new to closed

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

related to #5831 ?

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.