aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-08-02 06:35:37 +0300
committerFrederick Muriuki Muriithi2023-08-02 06:44:33 +0300
commit47c74f8ad6e76c4227ba1ff980d3a49f9ef79a81 (patch)
tree47136d51484446218960f7a5301ecb2f17d0e593 /wqflask
parent9f62caa68b541d683b2a744af19c0ad4c6d0d206 (diff)
downloadgenenetwork2-47c74f8ad6e76c4227ba1ff980d3a49f9ef79a81.tar.gz
Fix Bug: Unchanged Values Were Being Deleted
The original code (using the homebrew ORM system) would simply ignore values that were `None` when doing updates - the new code using direct queries was not. My (fredmanglis) initial fix to provide a default for values in DB that did not accept NULL was incorrect; instead, I needed to remove any key-value pairs from the incoming data that were set to `None` to fix the bug. The fix still feels incorrect: maybe we should do direct comparisons for all old-new value pairs, and set the data to be updated based on the differences, rather than relying on `None`s.
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/metadata_edits.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py
index 109ed65e..c78d8151 100644
--- a/wqflask/wqflask/metadata_edits.py
+++ b/wqflask/wqflask/metadata_edits.py
@@ -297,17 +297,19 @@ View the diffs <a href='{url}' target='_blank'>here</a>", "success")
)
}
)
- publication_ = {
- "pubmed_id": data_.get("pubmed-id"),
- "abstract": data_.get("abstract"),
- "authors": data_.get("authors", ""),
- "title": data_.get("title"),
- "journal": data_.get("journal"),
- "volume": data_.get("volume"),
- "pages": data_.get("pages"),
- "month": data_.get("month"),
- "year": data_.get("year", 0),
- }
+ publication_ = {
+ key: val for key, val in {
+ "pubmed_id": data_.get("pubmed-id"),
+ "abstract": data_.get("abstract"),
+ "authors": data_.get("authors"),
+ "title": data_.get("title"),
+ "journal": data_.get("journal"),
+ "volume": data_.get("volume"),
+ "pages": data_.get("pages"),
+ "month": data_.get("month"),
+ "year": data_.get("year"),
+ }.items() if val is not None
+ }
updated_publications = ""
with database_connection(get_setting("SQL_URI")) as conn:
existing_publication = (# fetch publication