From fcfdca8e7d2875f81d441a24d7b53ec12a04b4de Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Wed, 7 Sep 2022 15:20:24 +0200 Subject: [PATCH] Overriding AnsibleContext.resolve is not needed/allowed (#78714) https://github.com/pallets/jinja/pull/1393 https://github.com/pallets/jinja/pull/1544 ci_complete --- .../fragments/remove-ansiblecontext-resolve.yml | 2 ++ lib/ansible/template/__init__.py | 11 +---------- 2 files changed, 3 insertions(+), 10 deletions(-) create mode 100644 changelogs/fragments/remove-ansiblecontext-resolve.yml diff --git a/changelogs/fragments/remove-ansiblecontext-resolve.yml b/changelogs/fragments/remove-ansiblecontext-resolve.yml new file mode 100644 index 00000000000..e202650a7e1 --- /dev/null +++ b/changelogs/fragments/remove-ansiblecontext-resolve.yml @@ -0,0 +1,2 @@ +minor_changes: + - Remove the ``AnsibleContext.resolve`` method as its override is not necessary. Furthermore the ability to override the ``resolve`` method was deprecated in Jinja 3.0.0 and removed in Jinja 3.1.0. diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py index df187904972..32e68547358 100644 --- a/lib/ansible/template/__init__.py +++ b/lib/ansible/template/__init__.py @@ -327,7 +327,7 @@ class AnsibleUndefined(StrictUndefined): class AnsibleContext(Context): ''' - A custom context, which intercepts resolve() calls and sets a flag + A custom context, which intercepts resolve_or_missing() calls and sets a flag internally if any variable lookup returns an AnsibleUnsafe value. This flag is checked post-templating, and (when set) will result in the final templated result being wrapped in AnsibleUnsafe. @@ -359,15 +359,6 @@ class AnsibleContext(Context): if val is not None and not self.unsafe and self._is_unsafe(val): self.unsafe = True - def resolve(self, key): - ''' - The intercepted resolve(), which uses the helper above to set the - internal flag whenever an unsafe variable value is returned. - ''' - val = super(AnsibleContext, self).resolve(key) - self._update_unsafe(val) - return val - def resolve_or_missing(self, key): val = super(AnsibleContext, self).resolve_or_missing(key) self._update_unsafe(val)