From 4b156c19afbe91f9feb5a65e263b771fbf6502cc Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 1 Mar 2022 16:31:07 +0300 Subject: Fetch id's separately for the insertion edge-case * gn3/db/sample_data (get_sample_data_ids): Add an extra condition that caters for inserts: during inserts, joins won't work when fetching the strain_id, publishdata_id, and strain_name. In this case, just create 2 separate queries to do that work. --- gn3/db/sample_data.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gn3') diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py index a410978..e3e1676 100644 --- a/gn3/db/sample_data.py +++ b/gn3/db/sample_data.py @@ -68,6 +68,15 @@ def get_sample_data_ids(conn: Any, publishxref_id: int, (publishxref_id, phenotype_id, strain_name)) if _result := cursor.fetchone(): strain_id, publishdata_id, inbredset_id = _result + if not all([strain_id, publishdata_id, inbredset_id]): + # Applies for data to be inserted: + cursor.execute("SELECT DataId, InbredSetId FROM PublishXRef " + "WHERE Id = %s AND PhenotypeId = %s", + (publishxref_id, phenotype_id)) + publishdata_id, inbredset_id = cursor.fetchone() + cursor.execute("SELECT Id FROM Strain WHERE Name = %s", + (strain_name,)) + strain_id = cursor.fetchone() return (strain_id, publishdata_id, inbredset_id) -- cgit v1.2.3