From 32a9103fba0454338ad126125038d97e7d228ec5 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 24 Feb 2023 12:30:36 +0300 Subject: auth: resources: Fix query for data not linked to resources --- gn3/auth/authorisation/groups/views.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'gn3/auth/authorisation/groups') diff --git a/gn3/auth/authorisation/groups/views.py b/gn3/auth/authorisation/groups/views.py index d21466c..0e779eb 100644 --- a/gn3/auth/authorisation/groups/views.py +++ b/gn3/auth/authorisation/groups/views.py @@ -163,19 +163,22 @@ def unlinked_data(resource_type: str) -> Response: "SELECT group_id, dataset_type, " "trait_id AS dataset_or_trait_id FROM phenotype_resources") - ids_query = ("SELECT group_id, dataset_type, dataset_or_trait_id " - "FROM linked_group_data " - f"{type_filter} " - f"EXCEPT {except_filter} ") + ids_query = ( + "SELECT * FROM (" + "SELECT group_id, dataset_type, dataset_or_trait_id " + "FROM linked_group_data " + f"EXCEPT SELECT * FROM ({except_filter})" + f") {type_filter}") cursor.execute(ids_query) ids = cursor.fetchall() + print(f"THE IDS: {ids} ==> {type_filter}") if ids: clause = ", ".join(["(?, ?, ?)"] * len(ids)) data_query = ( "SELECT * FROM linked_group_data " "WHERE (group_id, dataset_type, dataset_or_trait_id) " - f"IN (VALUES {clause})") + f"IN (VALUES {clause}) ") params = tuple(item for sublist in ((row[0], row[1], row[2]) for row in ids) for item in sublist) -- cgit 1.4.1