Skip to content

Commit

Permalink
fix update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkent committed Aug 13, 2024
1 parent a3b8c14 commit aaf3ae1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions store/neurostore/resources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions store/neurostore/resources/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit aaf3ae1

Please sign in to comment.