diff --git a/common/database_helpers.py b/common/database_helpers.py index 204c78e8..958bdefb 100644 --- a/common/database_helpers.py +++ b/common/database_helpers.py @@ -20,6 +20,13 @@ def __init__(self, table): self.table = table self.base_query = self.session.query(table) + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + log.info("Closing DB session") + self.session.close() + @abstractmethod def execute_query(self): pass