Saving a draft with externalId as a draft gives 500
🐛 Bug Report
Creating a draft item having an externalId and then again saving it as a draft gives a 500 error.
🤔 Expected Behavior
No 500 error, item should be saved again as a draft.
😯 Current Behavior
It gives a 500 error could not execute statement; SQL [n/a]; constraint [item_external_ids_identifier_service_code_identifier_item_i_key]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
.
🧭 How to reproduce
- Login
- Create a new item, e.g. a tool
- Enter a title, a description and an externalId, e.g.
Id service
"Wikidata" andIdentifier
"1234" - Save as draft
- You will get a green successfully saved message and you stay in the edit form, now again "Save as draft" (you do not need to change anything)
- You will get a "500 - Internal Server Error"
Observations
In the database backend raises this sql-error:
DETAIL: Key (identifier_service_code, identifier, item_id)=(Wikidata, 1234, 48697) already exists.
STATEMENT: insert into item_external_ids (identifier, identifier_service_code, item_id, id) values ($1, $2, $3, $4)
Not sure, why this happens. There is clearly only one externalId set (tried it out with direct API calls having only one externalId) - but looking at the sql-error, it shouldn't do an insert but instead an update (or before delete the externalIds).
Edited by Klaus Illmayer