Skip to content

Commit

Permalink
Merge pull request #5505 from specify/issue-5471
Browse files Browse the repository at this point in the history
Avoid COJO verisioning error on COG form saving
  • Loading branch information
CarolineDenis authored Dec 20, 2024
2 parents f009a39 + 7e3aec2 commit 0f14f92
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion specifyweb/specify/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,8 @@ def update_obj(collection, agent, name: str, id, version, data: Dict[str, Any],
else:
obj.modifiedbyagent = agent

bump_version(obj, version)
_handle_special_update_priors(obj, data)
bump_version(obj, version)
obj.save(force_update=True)
auditlog.update(obj, agent, parent_obj, dirty)
for dep in dependents_to_delete:
Expand Down Expand Up @@ -836,6 +836,8 @@ def bump_version(obj, version) -> None:
manager = obj.__class__._base_manager
updated = manager.filter(pk=obj.pk, version=version).update(version=version+1)
if not updated:
if obj._meta.model_name in {'collectionobjectgroupjoin'}:
return # TODO: temporary solution to allow for multiple updates to the same cojo object
raise StaleObjectException("%s object %d is out of date" % (obj.__class__.__name__, obj.id))
obj.version = version + 1

Expand Down Expand Up @@ -1071,6 +1073,8 @@ def _save_cojo_prior(obj):
"""
if obj._meta.model_name in {'collectionobject', 'collectionobjectgroup'} and hasattr(obj, 'cojo'):
obj.cojo.save()
elif obj._meta.model_name in {'collectionobjectgroupjoin'}:
obj.save()

def _handle_special_save_priors(obj):
"""
Expand Down

0 comments on commit 0f14f92

Please sign in to comment.