diff options
author | Frederick Muriuki Muriithi | 2023-04-14 12:50:39 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-04-14 12:50:39 +0300 |
commit | 73863c8230df455dc433f8f10e2cee5edd8d8e58 (patch) | |
tree | 5d2013aa31481d96ce3f9b54686a6d64c6766dad /gn3/auth/db.py | |
parent | 7022a3145586a7e5298bf2bf50226eb63a51d563 (diff) | |
download | genenetwork3-73863c8230df455dc433f8f10e2cee5edd8d8e58.tar.gz |
auth: Disconnect module from flask application
To avoid application context errors in external scripts, disconnect the
`gn3.auth.db` module from the `flask.current_app` dependency.
Diffstat (limited to 'gn3/auth/db.py')
-rw-r--r-- | gn3/auth/db.py | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/gn3/auth/db.py b/gn3/auth/db.py index 3b1844a..b8c91e9 100644 --- a/gn3/auth/db.py +++ b/gn3/auth/db.py @@ -1,12 +1,11 @@ """Handle connection to auth database.""" import sqlite3 +import logging import contextlib from typing import Any, Callable, Iterator, Protocol import traceback -from flask import current_app as app - class DbConnection(Protocol): """Type annotation for a generic database connection object.""" def cursor(self) -> Any: @@ -51,14 +50,13 @@ def connection(db_path: str, row_factory: Callable = sqlite3.Row) -> Iterator[Db """Create the connection to the auth database.""" conn = sqlite3.connect(db_path) conn.row_factory = row_factory - if app.config["DEBUG"]: - conn.set_trace_callback(app.logger.debug) + conn.set_trace_callback(logging.debug) conn.execute("PRAGMA foreign_keys = ON") try: yield conn except sqlite3.Error as exc: conn.rollback() - app.logger.debug(traceback.format_exc()) + logging.debug(traceback.format_exc()) raise exc finally: conn.commit() @@ -72,7 +70,7 @@ def cursor(conn: DbConnection) -> Iterator[DbCursor]: yield cur except sqlite3.Error as exc: conn.rollback() - app.logger.debug(traceback.format_exc()) + logging.debug(traceback.format_exc()) raise exc finally: conn.commit() |