From aaf3ae1f7fdb0ffd32673518d120b425055ce29e Mon Sep 17 00:00:00 2001 From: James Kent Date: Tue, 13 Aug 2024 17:40:49 -0500 Subject: [PATCH] fix update logic --- store/neurostore/resources/base.py | 2 ++ store/neurostore/resources/data.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/store/neurostore/resources/base.py b/store/neurostore/resources/base.py index fca690a7..dc18f441 100644 --- a/store/neurostore/resources/base.py +++ b/store/neurostore/resources/base.py @@ -296,6 +296,8 @@ def update_or_create(cls, data, id=None, user=None, record=None, flush=True): return record data["user_id"] = current_user.external_id + if hasattr(record, "id"): + data["id"] = record.id # check to see if duplicate duplicate = cls.check_duplicate(data, record) if duplicate: diff --git a/store/neurostore/resources/data.py b/store/neurostore/resources/data.py index 107eb607..fc4e68f3 100644 --- a/store/neurostore/resources/data.py +++ b/store/neurostore/resources/data.py @@ -935,10 +935,15 @@ def join_tables(self, q, args): def check_duplicate(cls, data, record): study_id = data.get("study_id") + if hasattr(record, "id") and record.id == data.get("id"): + # not a duplicate, same record + return False + if hasattr(record, "study") and record.study: study = record.study else: study = Study.query.filter_by(id=study_id).first() + if not study: return False