diff options
author | Frederick Muriuki Muriithi | 2023-04-15 19:35:53 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-04-15 19:35:53 +0300 |
commit | dbf0f9f0d34c9969aa6ae76f556745a9eb122106 (patch) | |
tree | c0a992202155e354dfac8a829e5dea197ceeef25 /gn3/db_utils.py | |
parent | 2b7ecb52fa5f568d7d48fc324bae8231343543bd (diff) | |
download | genenetwork3-dbf0f9f0d34c9969aa6ae76f556745a9eb122106.tar.gz |
Decouple `gn3.db_utils` from `flask.current_app`.
Decouple the `gn3.db_utils` module from the global `flask.current_app` object,
ensuring that the database uri value is passed in as a required argument to
the `gn3.db_utils.database_connection` function.
Diffstat (limited to 'gn3/db_utils.py')
-rw-r--r-- | gn3/db_utils.py | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/gn3/db_utils.py b/gn3/db_utils.py index e9db10f..7d6a445 100644 --- a/gn3/db_utils.py +++ b/gn3/db_utils.py @@ -4,7 +4,6 @@ from typing import Any, Iterator, Protocol, Tuple from urllib.parse import urlparse import MySQLdb as mdb import xapian -from flask import current_app def parse_db_url(sql_uri: str) -> Tuple: @@ -25,15 +24,10 @@ class Connection(Protocol): ... -## We need to decouple current_app from this module and function, but since this -## function is used throughout the code, that will require careful work to update -## all the code to pass the `sql_uri` argument, and make it a compulsory argument -## rather than its current optional state. @contextlib.contextmanager -def database_connection(sql_uri: str = "") -> Iterator[Connection]: +def database_connection(sql_uri) -> Iterator[Connection]: """Connect to MySQL database.""" - host, user, passwd, db_name, port = parse_db_url( - sql_uri or current_app.config["SQL_URI"]) + host, user, passwd, db_name, port = parse_db_url(sql_uri) connection = mdb.connect(db=db_name, user=user, passwd=passwd or '', |