From 088b6181457ef4e528b7dcbf04b7aca29b274d1f Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 18 Jul 2023 11:16:23 +0300 Subject: Bug: Fetch group name by dataset_id Change the code to fetch the group name by the dataset ID, since according to usage[1] of the `retrieve_group_name` function, the value passed in is the `dataset_id` and not the `group_id`. Change the name from `retrieve_group_name` to `retrieve_phenotype_group_name` to more clearly indicate that this function concerns itself with the groups that relate to phenotypes. [1](https://github.com/genenetwork/genenetwork2/blob/1bbb0430732b7fa5102d7dcbda80ebda252f5424/wqflask/wqflask/metadata_edits.py) --- gn3/db/datasets.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'gn3/db') diff --git a/gn3/db/datasets.py b/gn3/db/datasets.py index 28fe0fe..9121ec2 100644 --- a/gn3/db/datasets.py +++ b/gn3/db/datasets.py @@ -38,22 +38,18 @@ def retrieve_sample_list(group: str): samplelist = headers[3:] return samplelist -def retrieve_group_name( - group_id: int, connection: Any): +def retrieve_phenotype_group_name(connection: Any, dataset_id: int): """ - Given the group id (InbredSet.Id in the database), retrieve its name + Given the dataset id (PublishFreeze.Id in the database), retrieve the name + of the group the dataset belongs to. """ query = ( - "SELECT Name " - "FROM InbredSet " - "WHERE " - "InbredSet.Id = %(group_id)s") + "SELECT iset.Name " + "FROM PublishFreeze AS pf INNER JOIN InbredSet AS iset " + "ON pf.InbredSetId=iset.Id " + "WHERE pf.Id = %(dataset_id)s") with connection.cursor() as cursor: - cursor.execute( - query, - { - "group_id": group_id - }) + cursor.execute(query, {"dataset_id": dataset_id}) res = cursor.fetchone() if res: return res[0] -- cgit v1.2.3