Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

templates: move the globals up to the Environment (Jinja2 3.0.0) #419

Merged
merged 2 commits into from
Aug 31, 2021

Conversation

aplanas
Copy link
Contributor

@aplanas aplanas commented Aug 30, 2021

What does this PR do?

When creating a Jinja2 environment, we populate the globals in the
Template object that we generate from the environment. This cause a
problem when there is a {% include "./file.sls" %} in the template, as
cannot find in the environment globals information like the "tpldir",
for example, making the relative path to be unresolved.

Seems that in Jinja2 2.X this behaviour is not present, so attaching the
globals to the Template will make the include to work, but since Jinja2
3.0.0 this is not the case. Maybe related with the re-architecture from
pallets/jinja#295

This patch populate the globals in the Environment level, making this
and other variables reachable by the Jinja templates.

Also fix a wrong call to TemplateNotFound

What issues does this PR fix or reference?

Fixes: #55159

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

Upstream: saltstack/salt#60811

The TemplateNotFound exception requires a parameter, name, that is
missing in one of the calls.

File "/usr/lib/python3.8/site-packages/salt/utils/jinja.py", line 158, in get_source
    raise TemplateNotFound
TypeError: __init__() missing 1 required positional argument: 'name'

This patch add the missing parameter in the raise call.

Signed-off-by: Alberto Planas <[email protected]>
When creating a Jinja2 environment, we populate the globals in the
Template object that we generate from the environment.  This cause a
problem when there is a {% include "./file.sls" %} in the template, as
cannot find in the environment globals information like the "tpldir",
for example, making the relative path to be unresolved.

Seems that in Jinja2 2.X this behaviour is not present, so attaching the
globals to the Template will make the include to work, but since Jinja2
3.0.0 this is not the case.  Maybe related with the re-architecture from
pallets/jinja#295

This patch populate the globals in the Environment level, making this
and other variables reachable by the Jinja templates.

Fix #55159

Signed-off-by: Alberto Planas <[email protected]>
Copy link
Contributor

@vzhestkov vzhestkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@vzhestkov vzhestkov merged commit 05e809f into openSUSE:openSUSE-3000.3 Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants