aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-06-02 12:20:33 -0500
committerFrederick Muriuki Muriithi2025-06-02 12:31:54 -0500
commit78734ae46a39189e51105807fdfcc33a4320c514 (patch)
treeca15930d993081366e3ea118ecb311b505466a8a
parent6870c08d484f482cc2f2501d28b474636dd0810d (diff)
downloadgn-uploader-78734ae46a39189e51105807fdfcc33a4320c514.tar.gz
Explicitly query for newly entered data.
The `cursor.executemany()` call only returned the last row that was inserted, rather than ALL the rows. This is not the correct thing to do, therefore, this commit fixes that by explicitly querying for all the newly entered data.
-rw-r--r--uploader/phenotypes/models.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/uploader/phenotypes/models.py b/uploader/phenotypes/models.py
index 2843d06..3e749c0 100644
--- a/uploader/phenotypes/models.py
+++ b/uploader/phenotypes/models.py
@@ -303,9 +303,13 @@ def create_new_phenotypes(conn: mdb.Connection,
cursor.executemany(
("INSERT INTO "
"Phenotype(Pre_publication_description, Original_description, Units, Authorized_Users) "
- "VALUES (%(id)s, %(description)s, %(units)s, 'robwilliams') "
- "RETURNING *"),
+ "VALUES (%(id)s, %(description)s, %(units)s, 'robwilliams')"),
tuple(batch))
+ paramstr = ", ".join(["%s"] * len(batch))
+ cursor.execute(
+ "SELECT * FROM Phenotype WHERE Pre_publication_description IN "
+ f"({paramstr})",
+ tuple(item["id"] for item in batch))
_phenos = _phenos + tuple({
"phenotype_id": row["Id"],
"id": row["Pre_publication_description"],
@@ -343,6 +347,14 @@ def save_phenotypes_data(
"RETURNING *"),
tuple(batch))
+ paramstr = ", ".join(["(%s, %s)"] * len(batch))
+ cursor.execute(f"SELECT * FROM {_table_details['table']} "
+ f"WHERE ({_table_details['DataIdCol']}, StrainId) "
+ f"IN ({paramstr})",
+ tuple(single for items in
+ ((item["data_id"], item["sample_id"])
+ for item in batch)
+ for single in items))
saved_data = saved_data + tuple(dict(row) for row in cursor.fetchall())
return saved_data