From 18f4682a27630bd81eb0b1514476c2cf0f663a63 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 12 Sep 2022 06:45:59 +0300 Subject: Check db resultset before indexing into it The assumption that the resultset will never be empty was leading to a lot of errors. --- wqflask/db/webqtlDatabaseFunction.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'wqflask/db') diff --git a/wqflask/db/webqtlDatabaseFunction.py b/wqflask/db/webqtlDatabaseFunction.py index 122c546f..878792b4 100644 --- a/wqflask/db/webqtlDatabaseFunction.py +++ b/wqflask/db/webqtlDatabaseFunction.py @@ -31,8 +31,9 @@ def retrieve_species(group): cursor.execute( "SELECT Species.Name FROM Species, InbredSet WHERE InbredSet.Name = %s AND InbredSet.SpeciesId = Species.Id", (group,)) - return cursor.fetchone()[0] - return result + results = cursor.fetchone() + if results and results[0]: + return results[0] def retrieve_species_id(group): -- cgit v1.2.3