From 47c74f8ad6e76c4227ba1ff980d3a49f9ef79a81 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 2 Aug 2023 06:35:37 +0300 Subject: 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. --- wqflask/wqflask/metadata_edits.py | 24 +++++++++++++----------- 1 file 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 here", "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 -- cgit v1.2.3