Deleting collectionobjectattachment via api endpoints

Hi,

Specify v7.9.6.2

Im trying to make use of the api specifically the delete endpoint for attachments and collectionobjectattachments.
When trying to delete the collectionobjectattachment i get this error back:

500

Undocumented Error: Internal Server Error

Response body

Download

{"exception": "AssertionError", "message": "attempt to add object with null id to audit log", "data": "None", "traceback": "Traceback (most recent call last):\n  File \"/opt/specify7/ve/lib/python3.8/site-packages/django/core/handlers/base.py\", line 181, in _get_response\n    response = wrapped_callback(request, *callback_args, **callback_kwargs)\n  File \"/opt/specify7/specifyweb/specify/views.py\", line 34, in wrapped\n    return view(request, *args, **kwargs)\n  File \"/opt/specify7/ve/lib/python3.8/site-packages/django/views/decorators/cache.py\", line 31, in _cache_controlled\n    response = viewfunc(request, *args, **kw)\n  File \"/opt/specify7/specifyweb/specify/views.py\", line 70, in view\n    return dispatch_func(request, *args, **kwargs)\n  File \"/opt/specify7/specifyweb/specify/api.py\", line 177, in resource_dispatch\n    delete_resource(request.specify_collection,\n  File \"/usr/lib/python3.8/contextlib.py\", line 75, in inner\n    return func(*args, **kwds)\n  File \"/opt/specify7/specifyweb/specify/api.py\", line 636, in delete_resource\n    return delete_obj(obj, version, collection=collection, agent=agent)\n  File \"/opt/specify7/specifyweb/specify/api.py\", line 660, in delete_obj\n    delete_obj(dep, version, parent_obj=obj, collection=collection, agent=agent, clean_predelete=clean_predelete)\n  File \"/opt/specify7/specifyweb/specify/api.py\", line 650, in delete_obj\n    auditlog.remove(obj, agent, parent_obj)\n  File \"/opt/specify7/specifyweb/specify/auditlog.py\", line 63, in remove\n    log_obj = self._log(auditcodes.REMOVE, obj, agent, parent_record)\n  File \"/opt/specify7/specifyweb/specify/auditlog.py\", line 89, in _log\n    assert obj.id is not None, \"attempt to add object with null id to audit log\"\nAssertionError: attempt to add object with null id to audit log\n"}

Any help would be great, thanks.

1 Like

Hi @ldam,

Thank you for reaching out!


At the moment, you can remove an attachment using two methods:

  1. Click on the attachment using the data entry forms and click :minus_: (minus) in the top left of the dialog to remove it

    From here, you can click Continue to confirm the deletion:

  2. Delete the parent object (e.g. Collection Object) and the application business logic will automatically handle the removal of any associated attachments.


It seems like there is an issue with the deletion logic when attempting to remove a {table}attachment record, regardless of whether or not it is for collectionobjectattachment. I was able to recreate your issue with the API and added an issue to GitHub to capture this:

You can update all collectionobjectattachment records to unlink them from their corresponding attachment record, then use the API to remove the attachment records directly. For now, once this is done, you would likely need to remove the collectionobjectattachment records using SQL. I’ve sent a message to one of our developers to see if there is another solution, and if so, I will send an update here.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.