From 78734ae46a39189e51105807fdfcc33a4320c514 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 2 Jun 2025 12:20:33 -0500 Subject: 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. --- uploader/phenotypes/models.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'uploader/phenotypes/models.py') 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 -- cgit v1.2.3