From 1acd3873f44e0edff055c07fbb6d11066920f379 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Tue, 4 Jan 2022 13:12:36 +0300 Subject: 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. --- gn3/db/traits.py | 7 +++++++ 1 file changed, 7 insertions(+) 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)"), -- cgit v1.2.3