From 016f6566fef7d13328510e44588d676763a93189 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20M=C3=A9nager?= <herve.menager@pasteur.fr>
Date: Fri, 17 Apr 2020 18:21:59 +0200
Subject: [PATCH] make sure we do not crash on best activity during compound
 validation

fix #207
---
 ippisite/ippidb/models.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py
index 8bc2aa9a..9104c31c 100644
--- a/ippisite/ippidb/models.py
+++ b/ippisite/ippidb/models.py
@@ -862,7 +862,11 @@ class Compound(AutoFillableModel):
         best_pXC50_activity = self.best_activity
         if best_pXC50_activity is None:
             return None
-        return self.compoundactivityresult_set.filter(activity=best_pXC50_activity)[0]
+        best_cars = self.compoundactivityresult_set.filter(activity=best_pXC50_activity)
+        if len(best_cars) > 0:
+            return best_cars[0]
+        else:
+            return None
 
     @property
     def bioch_tests_count(self):
-- 
GitLab