Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dve/core_engine/backends/metadata/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BaseReportingConfig(BaseModel):

"""

UNTEMPLATED_FIELDS: ClassVar[set[str]] = {"message"}
UNTEMPLATED_FIELDS: ClassVar[set[str]] = set()
"""Fields that should not be templated."""

emit: Optional[str] = None
Expand Down
15 changes: 14 additions & 1 deletion src/dve/core_engine/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
from dve.core_engine.type_hints import JSONable, TemplateVariables


class PreserveTemplateUndefined(jinja2.Undefined):
"""
Preserve the original template in instances where the value cannot be populated. Whilst this
may result in templates coming back in the FeedbackMessage object, it's more useful to know
exactly what should have been populated rather than just returning blank values.
"""
def __str__(self):
return "{{" + self._undefined_name + "}}"


class RuleTemplateError(ValueError):
"""A rule template error."""

Expand All @@ -21,7 +31,10 @@ def _raise_rule_templating_error(message: str) -> NoReturn:


T = TypeVar("T", bound=JSONable)
ENVIRONMENT = jinja2.Environment(autoescape=False)
ENVIRONMENT = jinja2.Environment(
autoescape=jinja2.select_autoescape(default_for_string=False),
undefined=PreserveTemplateUndefined,
)
ENVIRONMENT.globals["repr"] = repr
ENVIRONMENT.globals["str"] = str
ENVIRONMENT.globals["raise"] = _raise_rule_templating_error
Expand Down