Template deletion not possible if at least one dataset uses it
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 564
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 29
Description
It is not possible to delete a template when it is used by one or more datasets.
The delete button is present and clickable:
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the template deletion path and the PostgreSQL foreign-key error described in the issue. Trace how dataset and datasetfield references to the template are handled, then verify that deletion clears those references and removes the template without violating the constraint.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, postgresql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100