diff --git a/homeassistant/components/sensor/sql.py b/homeassistant/components/sensor/sql.py index 99da8c3c68033..395c082f9d2fe 100644 --- a/homeassistant/components/sensor/sql.py +++ b/homeassistant/components/sensor/sql.py @@ -126,6 +126,8 @@ def update(self): except sqlalchemy.exc.SQLAlchemyError as err: _LOGGER.error("Error executing query %s: %s", self._query, err) return + finally: + sess.close() for res in result: _LOGGER.debug(res.items()) @@ -141,5 +143,3 @@ def update(self): data, None) else: self._state = data - - sess.close()