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, when doing this in the frontend.
🤔 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
(does only create a 500 when doing this on GUI)
- 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
It seems, that we have an issue here that concerns frontend as well as backend. If trying to reproduce the issue without frontend and using only API calls, it works as expected and don't give a 500. Therefore I looked into the calls that frontend creates and I see a difference, that also leads in the API calls to an error: When saving it the second time as a draft, I would call in the API (assuming fNCigV
as the persistentId) PUT /api/tools-services/fNCigV?draft=true
(that's the way that does not inflicts a 500 error) but the frontend calls PUT /api/tools-services/fNCigV?persistentId=fNCigV&draft=true
and this prodcues a 500 error. I don't know, why frontend adds the parameter persistentId=fNCigV
and I don't know, what backend does with this additional parameter (it is not documented in Swagger, I can only assume, that it tries to do something like a merge, as the mentioned error in the current behavior section is connected to the 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)
Adding @stefan.probst for frontend, @tparkola for backend (what do you think, does it also sound like a backend error and should we create a dedicated issue?) and @lbarbot for reporting the error.