I encountered a weird situation today and not sure what triggered it.
Suddenly, all my sensors stopped recording data to the states
and statistics
tables for all my sensors – whether system defaults, MQTT, or any other integration. No new entries and no changes to existing entries (e.g., no last_changed_ts
updates either).
However, HA continued to otherwise seem to run normally with no high level log errors shown in the GUIand no ‘notifications’. Indeed, when looking at the sensor in the Overview
dashboard, the states would all say they were updated during the past few minutes – but the sensor values never changed.
My automations also seemed to stop running – ironically, even the one that I use to warn me of stale sensors.
The detailed logs (using ‘ha core logs’) showed thousands of entries of form:
2025-01-06 17:55:09.030 ERROR (Recorder) [homeassistant.components.recorder.core] SQLAlchemyError error processing task CommitTask()
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 894, in _process_one_task_or_event_or_recover
task.run(self)
~~~~~~~~^^^^^^
File "/usr/src/homeassistant/homeassistant/components/recorder/tasks.py", line 295, in run
instance._commit_event_session_or_retry() # noqa: SLF001
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 1193, in _commit_event_session_or_retry
self._commit_event_session()
~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 1219, in _commit_event_session
session.execute(
~~~~~~~~~~~~~~~^
update(States),
^^^^^^^^^^^^^^^
...<6 lines>...
],
^^
)
^
File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py", line 2362, in execute
return self._execute_internal(
~~~~~~~~~~~~~~~~~~~~~~^
statement,
^^^^^^^^^^
...<4 lines>...
_add_event=_add_event,
^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py", line 2247, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
self,
^^^^^
...<4 lines>...
conn,
^^^^^
)
^
File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/bulk_persistence.py", line 1627, in orm_execute_statement
result = _bulk_update(
mapper,
...<8 lines>...
enable_check_rowcount=enable_check_rowcount,
)
File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/bulk_persistence.py", line 357, in _bulk_update
persistence._emit_update_statements(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
base_mapper,
^^^^^^^^^^^^
...<6 lines>...
enable_check_rowcount=enable_check_rowcount,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/persistence.py", line 948, in _emit_update_statements
raise orm_exc.StaleDataError(
...<3 lines>...
)
sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'states' expected to update 7 row(s); 6 were matched.
This all resolved after restarting HA – and there doesn’t seem to be any (permanent) database corruption.
However, I don’t know what triggered the problem and why this failure was silent.
Any idea what caused these failures of the recorder component?
Has anyone else experienced this???
strong text