aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-07-12 15:46:53 +0300
committerFrederick Muriuki Muriithi2023-07-12 15:46:53 +0300
commite926411480c69c0c420fd3c781664120bfd8e21b (patch)
treeecd1637ba28dba2da971a3027b492a21ced3c9b0
parentf920f9ad6d74648a0f572f3e937cfe1ea6578b3f (diff)
downloadgenenetwork3-e926411480c69c0c420fd3c781664120bfd8e21b.tar.gz
Bug: Set the `data_exists` variable within the context manager
The `cursor.fetchone()` call that was used as the condition to the `if` was called outside of the context manager, and therefore would always give a non-truthy value at best and an inconsistent result at worst. This commit gets the value before the context manager has exited and stores it for later use.
-rw-r--r--gn3/db/sample_data.py7
1 files changed, 3 insertions, 4 deletions
diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py
index a3a6ded..140e62e 100644
--- a/gn3/db/sample_data.py
+++ b/gn3/db/sample_data.py
@@ -407,10 +407,9 @@ def insert_sample_data(
cursor.execute(
"SELECT Id FROM PublishData where Id = %s "
"AND StrainId = %s",
- (data_id, strain_id),
- )
- conn.commit()
- if cursor.fetchone(): # Data already exists
+ (data_id, strain_id))
+ data_exists = cursor.fetchone()
+ if data_exists: # Data already exists
return count
for header, value in zip(csv_header.split(","), data.split(",")):