diff options
| author | Frederick Muriuki Muriithi | 2026-02-06 16:57:18 -0600 |
|---|---|---|
| committer | Frederick Muriuki Muriithi | 2026-02-06 16:57:18 -0600 |
| commit | f91869500b0cb2ebeb785ee13464cad9aefba801 (patch) | |
| tree | f20cc8fd4f1d68ba3901f11478f8a79342ec4c01 | |
| parent | 4c2fc30507fdb419e33caabc6b2cb07d2689df4e (diff) | |
| download | gn-auth-f91869500b0cb2ebeb785ee13464cad9aefba801.tar.gz | |
Fetch a single resource ID: delete data from one resource at a time.
| -rw-r--r-- | gn_auth/auth/authorisation/data/phenotypes.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/gn_auth/auth/authorisation/data/phenotypes.py b/gn_auth/auth/authorisation/data/phenotypes.py index d335314..91f761a 100644 --- a/gn_auth/auth/authorisation/data/phenotypes.py +++ b/gn_auth/auth/authorisation/data/phenotypes.py @@ -206,6 +206,23 @@ def fetch_data_link_ids( return tuple(uuid.UUID(row["data_link_id"]) for row in cursor.fetchall()) +def fetch_resource_id(cursor: authdb.DbCursor, + data_link_ids: tuple[uuid.UUID, ...]) -> uuid.UUID: + """Retrieve the ID of the resource where the data is linked to. + + RAISES: InvalidResourceError in the case where more the data_link_ids belong + to more than one resource.""" + _paramstr = ", ".join(["?"] * len(data_link_ids)) + cursor.execute( + "SELECT DISTINCT(resource_id) FROM phenotype_resources " + f"WHERE data_link_id IN ({_paramstr})", + tuple(str(_id) for _id in data_link_ids)) + _ids = tuple(uuid.UUID(row['resource_id']) for row in cursor.fetchall()) + if len(_ids) != 1: + raise InvalidResourceError("...") + return _ids[0] + + def delete_linked_data( cursor: authdb.DbCursor, data_link_ids: tuple[uuid.UUID, ...] @@ -248,6 +265,7 @@ def delete_linked_phenotypes_data( # TODO: Use background job, for huge number of xref_ids data_link_ids = fetch_data_link_ids( cursor, species_id, population_id, dataset_id, xref_ids) + resource_id = fetch_resource_id(cursor, data_link_ids) _resources_ids = unlink_from_resources(cursor, data_link_ids) delete_resources(cursor, _resources_ids) _deleted = delete_linked_data(cursor, data_link_ids) |
