about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2026-04-07 13:53:21 -0500
committerFrederick Muriuki Muriithi2026-04-07 13:54:01 -0500
commitb2e870ccb3cd82f8ba28a578144c20fa6a636221 (patch)
treea5bde141875d7c7bcdf6563ed1dec2c7deb5e2c2
parent5e4f320440f4cb49ebc61b286a1baebc5f66740f (diff)
downloadgn-auth-b2e870ccb3cd82f8ba28a578144c20fa6a636221.tar.gz
Handle edge case where no admins exist: e.g. database is empty.
-rw-r--r--migrations/auth/20260402_01_Bf8nm-add-user-and-time-tracking-to-resources-table.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/migrations/auth/20260402_01_Bf8nm-add-user-and-time-tracking-to-resources-table.py b/migrations/auth/20260402_01_Bf8nm-add-user-and-time-tracking-to-resources-table.py
index fd1e617..702c418 100644
--- a/migrations/auth/20260402_01_Bf8nm-add-user-and-time-tracking-to-resources-table.py
+++ b/migrations/auth/20260402_01_Bf8nm-add-user-and-time-tracking-to-resources-table.py
@@ -38,7 +38,9 @@ def fetch_a_sysadmin_id(conn, resources_table):
             return tuple(row[0] for row in cursor.fetchall())
 
     if not bool(__admin_id__):
-        __admin_id__ = random.choice(__fetch__())
+        __admins__ = __fetch__()
+        if len(__admins__) > 0:
+            __admin_id__ = random.choice(__admins__)
 
     return __admin_id__