Skip to content

Commit

Permalink
Add logging, set to None when closing DB connection
Browse files Browse the repository at this point in the history
  • Loading branch information
1kastner committed Jan 13, 2022
1 parent 9526b45 commit 14b5c86
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion conflowgen/api/database_chooser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import List, Optional

from peewee import SqliteDatabase
Expand All @@ -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 ``<project root>/data/databases/``.
"""
self.logger = logging.getLogger("conflowgen")
self.sqlite_database_connection = SqliteDatabaseConnection(
sqlite_databases_directory=sqlite_databases_directory
)
Expand Down Expand Up @@ -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

0 comments on commit 14b5c86

Please sign in to comment.