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.
This commit is contained in:
Justin Paupore 2021-04-06 11:39:54 -07:00 committed by GitHub
parent 42d2039560
commit c4f9489d61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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