Fail when rendering undefined objects in Jinja2 templates
By not successfully rendering unknown objects to an empty string the caller provided error_value actually gets used. This allows, for instance, the MQTT sensor to retain its state when an unexpected or unwanted message (#2733/#3834) is received.
This commit is contained in:
1 parent
18f5258aaf
commit
c8add59ea5
2 files changed
+2
-2
No files matched your search
@@ -402,7 +402,7 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment):
|
||||
"""Test if callback is safe."""
|
||||
return isinstance(obj, AllStates) or super().is_safe_callable(obj)
|
||||
|
||||
ENV = TemplateEnvironment()
|
||||
ENV = TemplateEnvironment(undefined=jinja2.StrictUndefined)
|
||||
ENV.filters['round'] = forgiving_round
|
||||
ENV.filters['multiply'] = multiply
|
||||
ENV.filters['timestamp_custom'] = timestamp_custom
|
||||
|
||||
Reference in new issue
Block a user