Skip to content

Commit 8aa9ac8

Browse files
fix: fix issue where templated error messages would not correctly format when passing in parameter values
1 parent 1b66735 commit 8aa9ac8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/dve/core_engine/backends/metadata/reporting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class BaseReportingConfig(BaseModel):
2828
2929
"""
3030

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

3434
emit: Optional[str] = None

src/dve/core_engine/templating.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
from dve.core_engine.type_hints import JSONable, TemplateVariables
1212

1313

14+
class PreserveTemplateUndefined(jinja2.Undefined):
15+
"""
16+
Preserve the original template in instances where the value cannot be populated. Whilst this
17+
may result in templates coming back in the FeedbackMessage object, it's more useful to know
18+
exactly what should have been populated rather than just returning blank values.
19+
"""
20+
def __str__(self):
21+
return "{{" + self._undefined_name + "}}"
22+
23+
1424
class RuleTemplateError(ValueError):
1525
"""A rule template error."""
1626

@@ -21,7 +31,8 @@ def _raise_rule_templating_error(message: str) -> NoReturn:
2131

2232

2333
T = TypeVar("T", bound=JSONable)
24-
ENVIRONMENT = jinja2.Environment(autoescape=False)
34+
# ENVIRONMENT = jinja2.Environment(autoescape=False)
35+
ENVIRONMENT = jinja2.Environment(autoescape=False, undefined=PreserveTemplateUndefined)
2536
ENVIRONMENT.globals["repr"] = repr
2637
ENVIRONMENT.globals["str"] = str
2738
ENVIRONMENT.globals["raise"] = _raise_rule_templating_error

0 commit comments

Comments
 (0)