IQSS / dataverse

Open source research data repository software
http://dataverse.org
Other
882 stars 494 forks source link

Template deletion not possible if at least one dataset uses it #11008

Open stevenferey opened 1 week ago

stevenferey commented 1 week ago

It is not possible to delete a template when it is used by one or more datasets.

The delete button is present and clickable:

Capture d’écran du 2024-11-08 16-00-26

After a deletion request, nothing is deleted from the interface, but an error appears in the server logs:

Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 4.0.1.payara-p1.v202304041433): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: update or delete on table "template" violates foreign key constraint "fx_dataset_template_id" on table "dataset"
  Detail: Key (id)=(222) is still referenced from table "dataset".
Error Code: 0
Call: DELETE FROM TEMPLATE WHERE (ID = ?)
    bind => [1 parameter bound]
Query: DeleteObjectQuery(edu.harvard.iq.dataverse.Template@de)

Proposed solution:

when deleting a template, set the template_id of the dataset and datasetfield to null. The SQL constraint will be respected and the deletion can be performed.