aboutsummaryrefslogtreecommitdiff
path: root/gn3/db/sample_data.py
diff options
context:
space:
mode:
authorBonfaceKilz2022-03-02 15:41:02 +0300
committerBonfaceKilz2022-03-12 15:33:09 +0300
commit5a20d1a42990dc97c47ed4e7da286494693a7a05 (patch)
tree2d508708ea8d6a18dac919c1940d0476ad139d30 /gn3/db/sample_data.py
parentba006bdd5ae2053575e11539186d5c5041f070c1 (diff)
downloadgenenetwork3-5a20d1a42990dc97c47ed4e7da286494693a7a05.tar.gz
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.
Diffstat (limited to 'gn3/db/sample_data.py')
-rw-r--r--gn3/db/sample_data.py15
1 files changed, 10 insertions, 5 deletions
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,