about summary refs log tree commit diff
path: root/gn3/db/traits.py
diff options
context:
space:
mode:
authorBonfaceKilz2022-01-04 13:12:36 +0300
committerBonfaceKilz2022-01-04 17:04:28 +0300
commit1acd3873f44e0edff055c07fbb6d11066920f379 (patch)
treeeb5fd389f4101dd2694561f8a433d47d1d1598bc /gn3/db/traits.py
parent6bb51023032281f28736a4c761fa50e3072327e1 (diff)
downloadgenenetwork3-1acd3873f44e0edff055c07fbb6d11066920f379.tar.gz
traits.py: Return early during an insert if the give record exists
Sometimes, a user will try to insert data twice, on in some instances, 2
different users will attempt the same inserts of the same records separately.
In such cases, ignore the insert, and return early.
Diffstat (limited to 'gn3/db/traits.py')
-rw-r--r--gn3/db/traits.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/gn3/db/traits.py b/gn3/db/traits.py
index 9d5ddd1..2cab94e 100644
--- a/gn3/db/traits.py
+++ b/gn3/db/traits.py
@@ -259,6 +259,13 @@ def insert_sample_data(conn: Any, #pylint: disable=[R0913]
                            (strain_name,))
             strain_id = cursor.fetchone()
 
+            # Return early if an insert already exists!
+            cursor.execute("SELECT Id FROM PublishData where Id = %s "
+                           "AND StrainId = %s AND value = %s ",
+                           (data_id, strain_id, value))
+            if cursor.fetchone():  # This strain already exists
+                return (0, 0, 0)
+
             # Insert the PublishData table
             cursor.execute(("INSERT INTO PublishData (Id, StrainId, value)"
                             "VALUES (%s, %s, %s)"),