about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-05-30 13:33:03 -0500
committerFrederick Muriuki Muriithi2025-05-30 13:33:03 -0500
commitf2b07d7351cc377c904f5ba9654ed85165ff8962 (patch)
tree86879e7e81ddacbf2222b5549ee583a64854dedf
parent5468d86534139c6b8120eb5fb8093747ac3bc9fa (diff)
downloadgn-uploader-f2b07d7351cc377c904f5ba9654ed85165ff8962.tar.gz
Bug: Loop until the data is exhausted.
-rw-r--r--uploader/phenotypes/models.py13
1 files 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']}) "