From b18de873dbead76276ee5077bc8a2afe78f61606 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Wed, 6 Apr 2022 16:36:52 +0300 Subject: Use case attribute id inside brackets if present during insertions * gn3/db/sample_data.py (delete_sample_data): If an id is present in the column header, use it. * tests/unit/db/test_sample_data.py (test_delete_sample_data): Update tests to capture the above. --- gn3/db/sample_data.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'gn3/db') diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py index 518d2a2..de90162 100644 --- a/gn3/db/sample_data.py +++ b/gn3/db/sample_data.py @@ -275,14 +275,23 @@ def delete_sample_data( def __delete_case_attribute(conn, strain_id, case_attr, inbredset_id): with conn.cursor() as cursor: - cursor.execute( - "DELETE FROM CaseAttributeXRefNew " - "WHERE StrainId = %s AND CaseAttributeId = " - "(SELECT CaseAttributeId FROM " - "CaseAttribute WHERE Name = %s) " - "AND InbredSetId = %s", - (strain_id, case_attr, inbredset_id), - ) + (id_, name) = parse_csv_column(case_attr) + if id_: + cursor.execute( + "DELETE FROM CaseAttributeXRefNew " + "WHERE StrainId = %s AND CaseAttributeId = %s " + "AND InbredSetId = %s", + (strain_id, id_, inbredset_id), + ) + else: + cursor.execute( + "DELETE FROM CaseAttributeXRefNew " + "WHERE StrainId = %s AND CaseAttributeId = " + "(SELECT CaseAttributeId FROM " + "CaseAttribute WHERE Name = %s) " + "AND InbredSetId = %s", + (strain_id, name, inbredset_id), + ) return cursor.rowcount strain_id, data_id, inbredset_id = get_sample_data_ids( -- cgit v1.2.3