DebugUndefined does not handle object.value replacements
TheDarkFlame opened this issue · comments
Description
when using object.value syntax, undefined.DebugUndefined breaks instead of returning the missing substitution. If the parent object is defined, it returns the python object access error. If the parent object is not defined, it throws an error (like with default undefined)
Code Replication
import jinja2
template = jinja2.Environment(undefined=jinja2.DebugUndefined).from_string("env.val is {{ env.val }}")
print(template.render({'env': {'val': 'something'}}))
print(template.render({'env': {}}))
print(template.render({'other': 'something'}))
Expected Results
env.val is something
env.val is {{ env.val }}
env.val is {{ env.val }}
Actual Results
env.val is something
env.val is {{ no such element: dict object['val'] }}
Traceback (most recent call last):
File "/Users/taapadak/Work/opsgenie-kafka/jinjaissue.yml.py", line 5, in <module>
print(template.render({'other': 'something'}))
File "/Users/taapadak/Work/opsgenie-kafka/venv/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/Users/taapadak/Work/opsgenie-kafka/venv/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "/Users/taapadak/Work/opsgenie-kafka/venv/lib/python3.9/site-packages/jinja2/environment.py", line 485, in getattr
return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'env' is undefined
Environment
- Python version: 3.9.6
- Jinja version: Jinja2==3.1.2