You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ cat common
{% set var1 = ENV('HOME') %}
$ cat file1
{% include 'file2' %}
$ cat file2
{% import 'common' as COMMON %}
{{ COMMON.var1 }}
To repro the issue:
$ python3 test.py file2
jinja2 version: 3.1.3
/root
$ python3 test.py file1
jinja2 version: 3.1.3
Traceback (most recent call last):
File "/root/void/python/jinja/t1/test.py", line 10, in <module>
print(tmpl.render() )
^^^^^^^^^^^^^
File "/usr/local/py3/lib/python3.11/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/usr/local/py3/lib/python3.11/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "file1", line 1, in top-level template code
{% include 'file2' %}
^^^^^^^^^^^^^^^^^^^^^^
File "file2", line 1, in top-level template code
{% import 'common' as COMMON %}
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py3/lib/python3.11/site-packages/jinja2/environment.py", line 1405, in make_module
return TemplateModule(self, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py3/lib/python3.11/site-packages/jinja2/environment.py", line 1535, in __init__
body_stream = list(template.root_render_func(context))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "common", line 1, in top-level template code
{% set var1 = ENV('HOME') %}
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/py3/lib/python3.11/site-packages/jinja2/utils.py", line 83, in from_obj
if hasattr(obj, "jinja_pass_arg"):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'ENV' is undefined
As we can see, python3 test.py file2 works but python3 test.py file1 fails.
The text was updated successfully, but these errors were encountered:
davidism
changed the title
[v3.x] Template globals not visible in {% import %}'ed file when it's {% include %}'ed by another file
Template globals not visible in {% import %}'ed file when it's {% include %}'ed by another file
Feb 20, 2024
I've come up with the following minimal repro steps.
Python script:
Data files:
To repro the issue:
As we can see,
python3 test.py file2
works butpython3 test.py file1
fails.The text was updated successfully, but these errors were encountered: