Skip to content

Conversation

@tzoiker
Copy link

@tzoiker tzoiker commented Nov 17, 2021

Due to security issues we decided to migrate from jinja to mustache. Jinja supports error raising for missing variables, which is good for data validation purposes. Proposition:

  • Add error flag to render (incompatible with keep, warn);
  • Raise UndefinedError only for variable, no escape, partial.

@lekhnath
Copy link

When will this get merged?

@Cayan
Copy link

Cayan commented Aug 23, 2023

I'm using the following logic to validate if there are missing variables:

rendered_content = chevron.render(template, context)

# Find all variables in the template
variables = re.findall(r'{{\s*([\w.]+)\s*}}', template)

# Check if any variable resulted in an empty string
for var in variables:
    var_rendered = chevron.render("{{" + var + "}}", context)
    if var_rendered == "":
        raise Exception(f"Variable '{var}' is missing from context or resulted in an empty string.")

@seittema
Copy link

@noahmorrison Any indication if this can/will get merged? We are in need of this behavior as well to be able to catch an exception when a there is a missing variables as that indicates there's a bug and we do not want to silently continue

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

Successfully merging this pull request may close these issues.

4 participants