The 3a86ef3 commit breaks traceback line numbers on Python 3.7. (On Django, this breaks the debug traceback view altogether.)
Refs:
Thanks to @tomhamiltonstubber for the original minimal example.
Expected Behavior
Tracebacks should have correct line numbers, and source lines should be retrievable.
Actual Behavior
Tracebacks within Jinja templates have incorrect line numbers, and source is not retrievable.
Python Code
import jinja2
l = jinja2.FileSystemLoader('.')
e = jinja2.Environment(loader=l)
t = e.get_template('index.jinja')
print(t.render({'foo': [8]}))
Template Code
{% block content %}
{% for x, y in foo %}
{{ x }}
{% endfor %}
{% endblock %}
Full Traceback
Traceback (most recent call last):
File "test.py", line 7, in <module>
print(t.render({'foo': [8]}))
File "jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "./index.jinja", line 1, in top-level template code
{% block content %}
File "jinja2/environment.py", line 1005, in render
return concat(self.root_render_func(self.new_context(vars)))
File "./index.jinja", line 10, in root
File "./index.jinja", line 19, in block_content
TypeError: cannot unpack non-iterable int object
There are only 5 lines in index.jinja and the tracebacks point to line 10 and 19.
If one cheats Jinja to use the old hack on Python 3.7, things work:
import sys
sys.version_info = (3, 6) # don't do this at home
import jinja2
l = jinja2.FileSystemLoader('.')
e = jinja2.Environment(loader=l)
t = e.get_template('index.jinja')
print(t.render({'foo': [8]}))
Traceback (most recent call last):
File "test.py", line 9, in <module>
print(t.render({'foo': [8]}))
File "jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "./index.jinja", line 1, in top-level template code
{% block content %}
File "./index.jinja", line 2, in block "content"
{% for x, y in foo %}
TypeError: cannot unpack non-iterable int object
Your Environment
- Python version: Python 3.7.4 (default, Oct 12 2019, 18:55:28) [Clang 11.0.0 (clang-1100.0.33.8)] on darwin
- Jinja version: 2.10.3
The 3a86ef3 commit breaks traceback line numbers on Python 3.7. (On Django, this breaks the debug traceback view altogether.)
Refs:
Thanks to @tomhamiltonstubber for the original minimal example.
Expected Behavior
Tracebacks should have correct line numbers, and source lines should be retrievable.
Actual Behavior
Tracebacks within Jinja templates have incorrect line numbers, and source is not retrievable.
Python Code
Template Code
Full Traceback
There are only 5 lines in
index.jinjaand the tracebacks point to line 10 and 19.If one cheats Jinja to use the old hack on Python 3.7, things work:
Your Environment