From 14b5c869d8a5e119a00fd765480792e97e54c052 Mon Sep 17 00:00:00 2001 From: Marvin Kastner Date: Thu, 13 Jan 2022 16:01:34 +0100 Subject: [PATCH] Add logging, set to None when closing DB connection --- conflowgen/api/database_chooser.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/conflowgen/api/database_chooser.py b/conflowgen/api/database_chooser.py index 4dc2c539..4bec745e 100644 --- a/conflowgen/api/database_chooser.py +++ b/conflowgen/api/database_chooser.py @@ -1,3 +1,4 @@ +import logging from typing import List, Optional from peewee import SqliteDatabase @@ -22,6 +23,7 @@ def __init__(self, sqlite_databases_directory: Optional[str] = None): sqlite_databases_directory: The DatabaseChooser opens one directory. All databases are saved to and load from this directory. It defaults to ``/data/databases/``. """ + self.logger = logging.getLogger("conflowgen") self.sqlite_database_connection = SqliteDatabaseConnection( sqlite_databases_directory=sqlite_databases_directory ) @@ -73,10 +75,11 @@ def close_current_connection(self) -> None: Close current connection, e.g. as a preparatory step to create a new SQLite database. """ if self.peewee_sqlite_db: - self.peewee_sqlite_db.close() + self._close_and_reset_db() else: raise NoCurrentConnectionException("You must first create a connection to an SQLite database.") def _close_and_reset_db(self): + self.logger.debug("Closing current database connection.") self.peewee_sqlite_db.close() self.peewee_sqlite_db = None