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
Don't overwrite builtin jinja2 filters with tests #37881
Conversation
* Don't overwrite builtin jinja2 filters with tests. Fixes ansible#37856 * Fix tests and other callers of _get_filters (cherry picked from commit 1f824bd)
@@ -176,7 +176,7 @@ def generic_visit(self, node, inside_call=False, inside_yield=False): | |||
) | |||
try: | |||
e = templar.environment.overlay() | |||
e.filters.update(templar._get_filters()) | |||
e.filters.update(templar._get_filters(e.filters)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could reverse the update ordering and update templar._get_filters() (or a copy...) with e.filters so that
the e.filters 'wins'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like
custom_filters = templar._get_filters()
custom_filters.update(e.filters)
e.filters = custom_filters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to override a builtin filter with an ansible provided by filter, such as groupby
. We just don't want this to happen with custom tests.
Eventually custom tests will no longer be registered as filters (2.9), but have been kept thus far for backwards compat.
* Don't overwrite builtin jinja2 filters with tests. Fixes ansible#37856 * Fix tests and other callers of _get_filters
The abs test for absolute paths overwrites the built-in Jinja2 abs filter, preventing the absolute value of numbers from being taken and breaking existing code which makes use of the absolute value filter. Superceded by ansible#37881 in Ansible 2.6.
SUMMARY
Don't overwrite builtin jinja2 filters with tests. Fixes #37856
ISSUE TYPE
COMPONENT NAME
lib/ansible/template/init.py
ANSIBLE VERSION
ADDITIONAL INFORMATION