From 5a20d1a42990dc97c47ed4e7da286494693a7a05 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Wed, 2 Mar 2022 15:41:02 +0300 Subject: Check whether publish data already exists before inserting * gn3/db/sample_data.py (insert_sample_data): If data already exists in the table, do not attempt an insert; otherwise, an error will be generated. --- gn3/db/sample_data.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'gn3') diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py index e3e1676..7aacdc1 100644 --- a/gn3/db/sample_data.py +++ b/gn3/db/sample_data.py @@ -258,11 +258,16 @@ def insert_sample_data(conn: Any, # pylint: disable=[R0913] f"{_map.get(table)} " f"VALUES %s %s %s") with conn.cursor() as cursor: - cursor.execute((f"INSERT INTO {table} " - f"{_map.get(table)} " - f"VALUES (%s, %s, %s)"), - (strain_id, data_id, value)) - return cursor.rowcount + cursor.execute( + "SELECT Id FROM PublishData where Id = %s " + "AND StrainId = %s", + (data_id, strain_id)) + if not cursor.fetchone(): + cursor.execute((f"INSERT INTO {table} " + f"{_map.get(table)} " + f"VALUES (%s, %s, %s)"), + (strain_id, data_id, value)) + return cursor.rowcount return 0 def __insert_case_attribute(conn, strain_id, -- cgit v1.2.3