Open
Description
I hit this bug in two different ways, and I don't know if they have separate fixes or not.
The easy reproduction is, even accounting for the lack of positional-only arguments, passing a variable named self
to Template.render
does not work.
The more involved reproduction is, if there is a variable named self
in some context, (I encountered this in a macro, but presumably {% set self = "whatever" %}
would also work), then unlike other names, it is not visible in an {% include "blah" %}
.
import jinja2
ENVIRONMENT = jinja2.Environment(loader=jinja2.BaseLoader())
WORKING_TEMPLATE = ENVIRONMENT.from_string("{{ self_ }}")
BROKEN_TEMPLATE = ENVIRONMENT.from_string("{{ self }}")
print("Works:", WORKING_TEMPLATE.render({"self_": ":)"}))
print("Doesn't work:", BROKEN_TEMPLATE.render({"self": ":("}))
Output with Jinja2==3.1.4
:
Works: :)
Doesn't work: <TemplateReference None>
Expected output:
Works: :)
Doesn't work: :(
Environment:
- Python version: Python 3.12.3
- Jinja version: 3.1.4
Metadata
Metadata
Assignees
Labels
No labels
Activity