From aa8927c98cd3524b8a6ccff3270dc6dfad450f5a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 12 Feb 2023 11:40:55 -0600 Subject: [PATCH] Speed up loops with jinja templates (#87945) --- homeassistant/helpers/template.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 3c9040f050e..3509530c708 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -37,6 +37,7 @@ import async_timeout from awesomeversion import AwesomeVersion import jinja2 from jinja2 import pass_context, pass_environment, pass_eval_context +from jinja2.runtime import AsyncLoopContext, LoopContext from jinja2.sandbox import ImmutableSandboxedEnvironment from jinja2.utils import Namespace import voluptuous as vol @@ -2256,7 +2257,9 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment): def is_safe_attribute(self, obj, attr, value): """Test if attribute is safe.""" - if isinstance(obj, (AllStates, DomainStates, TemplateState)): + if isinstance( + obj, (AllStates, DomainStates, TemplateState, LoopContext, AsyncLoopContext) + ): return attr[0] != "_" if isinstance(obj, Namespace):