simpler fix

This commit is contained in:
Jan Suhr 2025-07-28 12:14:00 +02:00
parent 69d8c4674f
commit c4e3e32a11

View File

@ -22,29 +22,11 @@ try:
class Context(SandboxedEnvironment.context_class): class Context(SandboxedEnvironment.context_class):
def resolve_or_missing(self, key): def resolve_or_missing(self, key):
# Try to get from parent context first res = super().resolve_or_missing(key)
try: if not isinstance(res, Undefined):
res = super().resolve_or_missing(key) return res
if not isinstance(res, Undefined):
return res
except AttributeError:
# Fallback for older Jinja2 versions
try:
res = super().resolve(key)
if not isinstance(res, Undefined):
return res
except AttributeError:
_logger.debug(
"Neither resolve_or_missing nor resolve method available"
)
# If the key is not found in the normal context, try to resolve it as a reference
return self.parent["ref"](key) return self.parent["ref"](key)
# Keep the old method for backward compatibility
def resolve(self, key):
return self.resolve_or_missing(key)
class Environment(SandboxedEnvironment): class Environment(SandboxedEnvironment):
context_class = Context context_class = Context