From 97ca71becd68ed24cd685f359dbe7fc10ffb5bda Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 4 Jan 2022 13:21:58 +0300 Subject: Check for any double-inserts or double-deletions Track any double-inserts or double-deletions --- wqflask/wqflask/metadata_edits.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py index 3d450b36..5b2b1e1d 100644 --- a/wqflask/wqflask/metadata_edits.py +++ b/wqflask/wqflask/metadata_edits.py @@ -495,18 +495,27 @@ def approve_data(resource_id:str, file_name: str): value=value, error=se, count=count) + + n_deletions = 0 for deletion in (deletions := [d for d in sample_data.get("Deletions")]): strain_name, _, _, _ = deletion.split(",") - delete_sample_data( + __deletions, _, _ = delete_sample_data( conn=conn, trait_name=sample_data.get("trait_name"), strain_name=strain_name, phenotype_id=int(sample_data.get("phenotype_id"))) + if __deletions: + n_deletions += 1 + # Remove any data that already exists from sample_data deletes + else: + sample_data.get("Deletions").remove(deletion) + + n_insertions = 0 for insertion in ( insertions := [d for d in sample_data.get("Additions")]): (strain_name, value, se, count) = insertion.split(",") - insert_sample_data( + __insertions, _, _ = insert_sample_data( conn=conn, trait_name=sample_data.get("trait_name"), strain_name=strain_name, @@ -516,6 +525,11 @@ def approve_data(resource_id:str, file_name: str): count=count) if any([any(modifications), any(deletions), any(insertions)]): + if __insertions: + n_insertions += 1 + # Remove any data that already exists from sample_data inserts + else: + sample_data.get("Additions").remove(insertion) insert(conn, table="metadata_audit", data=MetadataAudit( -- cgit v1.2.3