From f2b07d7351cc377c904f5ba9654ed85165ff8962 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 30 May 2025 13:33:03 -0500 Subject: Bug: Loop until the data is exhausted. --- uploader/phenotypes/models.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/uploader/phenotypes/models.py b/uploader/phenotypes/models.py index e217699..498a48b 100644 --- a/uploader/phenotypes/models.py +++ b/uploader/phenotypes/models.py @@ -295,7 +295,11 @@ def create_new_phenotypes(conn: mdb.Connection, """Add entirely new phenotypes to the database.""" _phenos = tuple() with conn.cursor(cursorclass=DictCursor) as cursor: - for batch in take(phenotypes, 1000): + while True: + batch = take(phenotypes, 1000) + if len(batch) == 0: + break + cursor.executemany( ("INSERT INTO " "Phenotypes(Pre_publication_description, Original_description, Units, Authorized_Users) " @@ -325,7 +329,12 @@ def save_phenotypes_data( }[table] saved_data = tuple() with conn.cursor(cursorclass=DictCursor) as cursor: - for batch in take(data, 5000): + while True: + batch = take(data, 5000): + if len(batch) == 0: + logger.warning("Got an empty batch. This needs investigation.") + break + cursor.executemany( (f"INSERT INTO {_table_details['table']}" f"(Id, StrainId, {_table_details['valueCol']}) " -- cgit v1.2.3