diff options
author | Frederick Muriuki Muriithi | 2023-04-06 12:31:05 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-04-06 12:31:05 +0300 |
commit | 17abad9300e4a96a14f94da486ef8307f7d27e06 (patch) | |
tree | 38fe3bfd36be9a821adfc67b83fbbd587ceb8b5e /gn3 | |
parent | 3d873435f0d464864d4d691d6be4db40931fac05 (diff) | |
download | genenetwork3-17abad9300e4a96a14f94da486ef8307f7d27e06.tar.gz |
Remove deprecated `gn3.db_utils.database_connector` function
Remove the deprecated function and fix a myriad of bugs that arise from
removing the function.
Issue: https://issues.genenetwork.org/issues/bugfix_coupling_current_app_and_db_utils
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/api/async_commands.py | 4 | ||||
-rw-r--r-- | gn3/api/correlation.py | 4 | ||||
-rw-r--r-- | gn3/api/heatmaps.py | 6 | ||||
-rw-r--r-- | gn3/api/menu.py | 6 | ||||
-rw-r--r-- | gn3/commands.py | 5 | ||||
-rw-r--r-- | gn3/db_utils.py | 9 |
6 files changed, 14 insertions, 20 deletions
diff --git a/gn3/api/async_commands.py b/gn3/api/async_commands.py index c0cf4bb..da146b8 100644 --- a/gn3/api/async_commands.py +++ b/gn3/api/async_commands.py @@ -11,6 +11,6 @@ def command_state(command_id): state = rconn.hgetall(name=command_id) if not state: return jsonify( - status=404, - error="The command id provided does not exist.") + error="The command id provided does not exist.", + status="error"), 404 return jsonify(dict(state.items())) diff --git a/gn3/api/correlation.py b/gn3/api/correlation.py index 6e70899..eb4cc7d 100644 --- a/gn3/api/correlation.py +++ b/gn3/api/correlation.py @@ -9,7 +9,7 @@ from flask import request from flask import current_app from gn3.settings import SQL_URI -from gn3.db_utils import database_connector +from gn3.db_utils import database_connection from gn3.commands import run_sample_corr_cmd from gn3.responses.pcorrs_responses import build_response from gn3.commands import run_async_cmd, compose_pcorrs_command @@ -64,7 +64,7 @@ def compute_lit_corr(species=None, gene_id=None): might be needed for actual computing of the correlation results """ - with database_connector() as conn: + with database_connection(current_app.config["SQL_URI"]) as conn: target_traits_gene_ids = request.get_json() target_trait_gene_list = list(target_traits_gene_ids.items()) diff --git a/gn3/api/heatmaps.py b/gn3/api/heatmaps.py index 80c8ca8..26c165f 100644 --- a/gn3/api/heatmaps.py +++ b/gn3/api/heatmaps.py @@ -5,9 +5,9 @@ Module to hold the entrypoint functions that generate heatmaps import io from flask import jsonify from flask import request -from flask import Blueprint +from flask import Blueprint, current_app from gn3.heatmaps import build_heatmap -from gn3.db_utils import database_connector +from gn3.db_utils import database_connection heatmaps = Blueprint("heatmaps", __name__) @@ -24,7 +24,7 @@ def clustered_heatmaps(): return jsonify({ "message": "You need to provide at least two trait names." }), 400 - with database_connector() as conn: + with database_connection(current_app.config["SQL_URI"]) as conn: def parse_trait_fullname(trait): name_parts = trait.split(":") return f"{name_parts[1]}::{name_parts[0]}" diff --git a/gn3/api/menu.py b/gn3/api/menu.py index cc77ab8..58b761e 100644 --- a/gn3/api/menu.py +++ b/gn3/api/menu.py @@ -1,14 +1,14 @@ """API for data used to generate menus""" -from flask import jsonify, Blueprint +from flask import jsonify, Blueprint, current_app from gn3.db.menu import gen_dropdown_json -from gn3.db_utils import database_connector +from gn3.db_utils import database_connection menu = Blueprint("menu", __name__) @menu.route("/generate/json") def generate_json(): """Get the menu in the JSON format""" - with database_connector() as conn: + with database_connection(current_app.config["SQL_URI"]) as conn: return jsonify(gen_dropdown_json(conn)) diff --git a/gn3/commands.py b/gn3/commands.py index 0e78fd2..a90e895 100644 --- a/gn3/commands.py +++ b/gn3/commands.py @@ -14,6 +14,8 @@ from typing import Tuple from typing import Union from typing import Sequence from uuid import uuid4 + +from flask import current_app from redis.client import Redis # Used only in type hinting from gn3.chancy import random_string @@ -80,7 +82,8 @@ def compose_pcorrs_command( prefix_cmd = ( f"{sys.executable}", "-m", "scripts.partial_correlations", - primary_trait, ",".join(control_traits), __parse_method__(method)) + primary_trait, ",".join(control_traits), __parse_method__(method), + current_app.config["SQL_URI"]) if ( kwargs.get("target_database") is not None and kwargs.get("target_traits") is None): diff --git a/gn3/db_utils.py b/gn3/db_utils.py index 4827358..e9db10f 100644 --- a/gn3/db_utils.py +++ b/gn3/db_utils.py @@ -17,15 +17,6 @@ def parse_db_url(sql_uri: str) -> Tuple: parsed_db.path[1:], parsed_db.port) -# This function is deprecated. Use database_connection instead. -def database_connector(sql_uri: str = "") -> mdb.Connection: - """function to create db connector""" - host, user, passwd, db_name, db_port = parse_db_url( - sql_uri or current_app.config["SQL_URI"]) - - return mdb.connect(host, user, passwd, db_name, port=(db_port or 3306)) - - # pylint: disable=missing-class-docstring, missing-function-docstring, too-few-public-methods class Connection(Protocol): """Type Annotation for MySQLdb's connection object""" |