diff options
author | BonfaceKilz | 2022-04-06 16:36:52 +0300 |
---|---|---|
committer | BonfaceKilz | 2022-04-07 11:54:28 +0300 |
commit | b18de873dbead76276ee5077bc8a2afe78f61606 (patch) | |
tree | d432548c9bb820653cb03e98324284f14bd699e1 /gn3 | |
parent | dc71058e894c9857de68c7844bfc4b813c0532da (diff) | |
download | genenetwork3-b18de873dbead76276ee5077bc8a2afe78f61606.tar.gz |
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.
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/db/sample_data.py | 25 |
1 files changed, 17 insertions, 8 deletions
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( |