Skip to content
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

DebugUndefined does not handle object.value replacements #1871

Open
TheDarkFlame opened this issue Jul 21, 2023 · 0 comments
Open

DebugUndefined does not handle object.value replacements #1871

TheDarkFlame opened this issue Jul 21, 2023 · 0 comments

Comments

@TheDarkFlame
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant