Hello,
I recently upgraded to the 2025.1 release from one over a year older, hoping that Jinja error messages had improved. But, at least in this instance, they haven’t, and I was hoping if anyone has some wisdom about how to get started.
Usually, I would handle errors of this sort by focusing on a recent change I made, and could usually figure out the problem by inspection or use of the Template editor. The problem with the latter approach is that for templates written to react to triggers and other stateful things, setting up the context in the Template editor is a pain that can be error-prone.
In this case, I can’t correlate the errors with a recent change, or even with similarly timed event triggers. And the error message doesn’t appear to actually reference any of my own code.
Does anyone have any suggestions about what type of runtime condition might trigger something like this? I’m in the process of shutting down parts of my YAML code to isolate the source of the problem, but I figured at minimum if there is some wisdom here I’d like to know it for future reference.
The error from the log is below. Thanks to anyone who tries to figure this out.
2025-01-21 11:54:00.285 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/template.py", line 643, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/template.py", line 2745, in _render_with_context
return template.render(**kwargs)
~~~~~~~~~~~~~~~^^^^^^^^^^
File "/srv/hass/lib/python3.13/site-packages/jinja2/environment.py", line 1295, in render
self.environment.handle_exception()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/srv/hass/lib/python3.13/site-packages/jinja2/environment.py", line 942, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 3, in top-level template code
File "/srv/hass/lib/python3.13/site-packages/jinja2/sandbox.py", line 293, in getitem
return obj[argument]
~~~^^^^^^^^^^
jinja2.exceptions.UndefinedError: None has no element 0
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/srv/hass/lib/python3.13/site-packages/homeassistant/components/template/coordinator.py", line 115, in _handle_triggered_with_script
if script_result := await self._script.async_run(run_variables, script_context):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/script.py", line 1801, in async_run
return await asyncio.shield(create_eager_task(run.async_run()))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/script.py", line 464, in async_run
await self._async_step(log_exceptions=False)
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/script.py", line 528, in _async_step
self._handle_exception(
~~~~~~~~~~~~~~~~~~~~~~^
ex, continue_on_error, self._log_exceptions or log_exceptions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/script.py", line 558, in _handle_exception
raise exception
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/script.py", line 526, in _async_step
await getattr(self, handler)()
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/script.py", line 1209, in _async_variables_step
self._variables = self._action[CONF_VARIABLES].async_render(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
self._hass, self._variables, render_as_defaults=False
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/script_variables.py", line 62, in async_render
rendered_variables[key] = template.render_complex(
~~~~~~~~~~~~~~~~~~~~~~~^
value, rendered_variables, limited
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/template.py", line 266, in render_complex
return value.async_render(variables, limited=limited, parse_result=parse_result)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/template.py", line 645, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: None has no element 0
2025-01-21 11:54:00.288 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/template.py", line 643, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/template.py", line 2745, in _render_with_context
return template.render(**kwargs)
~~~~~~~~~~~~~~~^^^^^^^^^^
File "/srv/hass/lib/python3.13/site-packages/jinja2/environment.py", line 1295, in render
self.environment.handle_exception()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/srv/hass/lib/python3.13/site-packages/jinja2/environment.py", line 942, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 3, in top-level template code
File "/srv/hass/lib/python3.13/site-packages/jinja2/sandbox.py", line 293, in getitem
return obj[argument]
~~~^^^^^^^^^^
jinja2.exceptions.UndefinedError: None has no element 0
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/srv/hass/lib/python3.13/site-packages/homeassistant/components/template/coordinator.py", line 115, in _handle_triggered_with_script
if script_result := await self._script.async_run(run_variables, script_context):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/script.py", line 1801, in async_run
return await asyncio.shield(create_eager_task(run.async_run()))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/script.py", line 464, in async_run
await self._async_step(log_exceptions=False)
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/script.py", line 528, in _async_step
self._handle_exception(
~~~~~~~~~~~~~~~~~~~~~~^
ex, continue_on_error, self._log_exceptions or log_exceptions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/script.py", line 558, in _handle_exception
raise exception
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/script.py", line 526, in _async_step
await getattr(self, handler)()
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/script.py", line 1209, in _async_variables_step
self._variables = self._action[CONF_VARIABLES].async_render(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
self._hass, self._variables, render_as_defaults=False
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/script_variables.py", line 62, in async_render
rendered_variables[key] = template.render_complex(
~~~~~~~~~~~~~~~~~~~~~~~^
value, rendered_variables, limited
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/template.py", line 266, in render_complex
return value.async_render(variables, limited=limited, parse_result=parse_result)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/hass/lib/python3.13/site-packages/homeassistant/helpers/template.py", line 645, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: None has no element 0