From c4f9489d6126c57bbdfd271bfb743e6c91795188 Mon Sep 17 00:00:00 2001 From: Justin Paupore Date: Tue, 6 Apr 2021 11:39:54 -0700 Subject: [PATCH] Fix infinite recursion in LazyState (#48719) If LazyState cannot parse the attributes of its row as JSON, it prints a message to the logger. Unfortunately, it passes `self` as a format argument to that message, which causes its `__repr__` method to be called, which then tries to retrieve `self.attributes` in order to display them. This leads to an infinite recursion and a crash of the entire core. To fix, send the database row to be printed in the log message, rather than the LazyState object that wraps around it. --- homeassistant/components/history/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/history/__init__.py b/homeassistant/components/history/__init__.py index 59fdcc7811b..09f459b32d6 100644 --- a/homeassistant/components/history/__init__.py +++ b/homeassistant/components/history/__init__.py @@ -715,7 +715,7 @@ class LazyState(State): self._attributes = json.loads(self._row.attributes) except ValueError: # When json.loads fails - _LOGGER.exception("Error converting row to state: %s", self) + _LOGGER.exception("Error converting row to state: %s", self._row) self._attributes = {} return self._attributes