aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-09-12 06:45:59 +0300
committerFrederick Muriuki Muriithi2022-09-12 06:45:59 +0300
commit18f4682a27630bd81eb0b1514476c2cf0f663a63 (patch)
tree38693342340285329cc1d8bdd2d9c9c4a20982d3 /wqflask
parent228a5545adb47fee0de22e55536ee612aab9be66 (diff)
downloadgenenetwork2-18f4682a27630bd81eb0b1514476c2cf0f663a63.tar.gz
Check db resultset before indexing into it
The assumption that the resultset will never be empty was leading to a lot of errors.
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/base/data_set.py15
-rw-r--r--wqflask/db/webqtlDatabaseFunction.py5
2 files changed, 13 insertions, 7 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py
index dda5e8f9..47c03b06 100644
--- a/wqflask/base/data_set.py
+++ b/wqflask/base/data_set.py
@@ -328,8 +328,11 @@ class DatasetGroup:
"InbredSet.InbredSetCode "
"FROM InbredSet WHERE Name = %s",
(dataset.name,))
- (self.name, self.id,
- self.genetic_type, self.code) = cursor.fetchone()
+ results = cursor.fetchone()
+ if results:
+ (self.name, self.id, self.genetic_type, self.code) = results
+ else:
+ self.name = name or dataset.name
if self.name == 'BXD300':
self.name = "BXD"
@@ -353,7 +356,9 @@ class DatasetGroup:
"SELECT MappingMethodId FROM "
"InbredSet WHERE Name= %s",
(self.name,))
- mapping_id = cursor.fetchone()[0]
+ results = cursor.fetchone()
+ if results and results[0]:
+ mapping_id = results[0]
if mapping_id == "1":
mapping_names = ["GEMMA", "QTLReaper", "R/qtl"]
elif mapping_id == "2":
@@ -1227,8 +1232,8 @@ def geno_mrna_confidentiality(ob):
f"AuthorisedUsers FROM {ob.type}Freeze WHERE Name = %s",
(ob.name,)
)
- result = cursor.fetchall()[0]
- if result:
+ result = cursor.fetchall()
+ if len(result) > 0 and result[0]:
return True
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):