diff --git a/homeassistant/components/recorder/core.py b/homeassistant/components/recorder/core.py index ba0e5ba17d1..91dc0a27ead 100644 --- a/homeassistant/components/recorder/core.py +++ b/homeassistant/components/recorder/core.py @@ -847,15 +847,14 @@ class Recorder(threading.Thread): assert self.event_session is not None self._commits_without_expire += 1 + self.event_session.commit() if self._pending_expunge: - self.event_session.flush() for dbstate in self._pending_expunge: # Expunge the state so its not expired # until we use it later for dbstate.old_state if dbstate in self.event_session: self.event_session.expunge(dbstate) self._pending_expunge = [] - self.event_session.commit() # We just committed the state attributes to the database # and we now know the attributes_ids. We can save