-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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) #60811
Conversation
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 saltstack#55159 Signed-off-by: Alberto Planas <[email protected]>
@aplanas Thanks for the fix, this also resolves another issue that was reported related to the changes that went into Jinja2 3.0.x. We'll want to add some additional tests for this scenario and move these existing tests over to Pytest. If you don't have time to migrate these tests, a member of the Salt core team can help out. |
Is it planned to backport this fix or is there a strong dependency between Jinja2 3.0 and salt? i.e. will it be required to upgrade salt version when a distribution starts using newer Jinja2? |
In my test the patch is safe to backport. I tested master with the patch against Jinja2 2.10.X, 2.11.X and 3.0.1. More tests are welcome (but note that the CI was green, and none is using 3.0.1) |
I've done a before and after comparison using the Formula team's pre-salted images. We've been downgrading Jinja2 until now, so all our instances have been working. There are a few issues with installing on Gentoo with the
|
Fix has been released: * saltstack/salt#60811 Maintain Jinja2 downgrades where necessary, as outlined here: * saltstack/salt#60811 (comment)
# [1.50.0](https://gitlab.com/saltstack-formulas/infrastructure/salt-image-builder/compare/v1.49.0...v1.50.0) (2021-09-02) ### Continuous Integration * **gitlab-ci:** deprecate `3000.9` ([3529c9b](https://gitlab.com/saltstack-formulas/infrastructure/salt-image-builder/commit/3529c9b8b8ddd37643d372bc8316599ebaa3d8a4)) ### Features * **dockerfile.*:** remove Jinja2 downgrade workaround where possible ([07a0d03](https://gitlab.com/saltstack-formulas/infrastructure/salt-image-builder/commit/07a0d0393b91b4cc4ac76c137178d7794151a890)), closes [/github.com/saltstack/salt/pull/60811#issuecomment-911772632](https://gitlab.com//github.com/saltstack/salt/pull/60811/issues/issuecomment-911772632)
We're not planning to back port any fixes at this time unless it's considered a CVE issue, which this one is not. This fix will be available in the Silicon release. |
I assume old OS may not have access to the new Jinja2. Might consider running test case against both versions, to ensure salt works with both? In house code or other software already installed may not support newer version, if salt supplies a new version and it overrides the existing version. |
This seems a reasonable policy, I think some special notes should be in the documentation for users to easily spot possible troubles, something like Or maybe in the dependencies where the Regards. |
…ltstack#60811) * jinja: fix TemplateNotFound missing name 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]> * templates: move the globals up to the Environment 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 saltstack#55159 Signed-off-by: Alberto Planas <[email protected]>
…ltstack#60811) * jinja: fix TemplateNotFound missing name 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]> * templates: move the globals up to the Environment 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 saltstack#55159 Bug-Debian: https://bugs.debian.org/996271 Origin: upstream, saltstack#60811 Signed-off-by: Alberto Planas <[email protected]>
…ltstack#60811) * jinja: fix TemplateNotFound missing name 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]> * templates: move the globals up to the Environment 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 saltstack#55159 Bug-Debian: https://bugs.debian.org/996271 Origin: upstream, saltstack#60811 Signed-off-by: Alberto Planas <[email protected]>
With default version 3003.3, you run into saltstack/salt#55159, which was fixed by saltstack/salt#60811 If you want to install from git master, it fails because py2-pip is unavailable - Alpine 3.11 was the last version to include py2-pip This PR changes the git master process to python3 and adds all requirements for a successful build
Check for problems associated with this bug: * saltstack/salt#60188 - Affects use of `grains`, `opts`, `pillar` & `salt` in Jinja. Fix was first available in `3004`: * saltstack/salt#60811 Use tests to apply the Jinja2 downgrade only where necessary (and to ensure that it is actually working).
…ltstack#60811) * jinja: fix TemplateNotFound missing name 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]> * templates: move the globals up to the Environment 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 saltstack#55159 Signed-off-by: Alberto Planas <[email protected]>
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