Error when publishing a draft with externalIds
Every now and then there was an error in the logfiles that also had an effect on publishing an item. The error lead to a 500 error on frontend and in the logfiles it said:
ERROR e.s.m.c.MarketplaceExceptionHandler.handleServerError - Runtime exception
org.springframework.dao.DataIntegrityViolationException: 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
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:298)
I'm now able to repeat the error on our stage instance (all using the frontend):
- Login as a moderator (I guess it will also happen if you login as contributor)
- Create an item, e.g. click on "Create Tool or service"
- Enter a title and a description
- Important: enter an "Id Service", e.g. chose "GitHub" and add as Identifier "test/test"
- Now "Save as draft"
- You should still see the edit forms,.
- If you now try to "Publish" the item, it will give you on frontend a 500 error
In the logfile you will see:
06-04-2022 12:11:58.107 [http-nio-8080-exec-6] WARN o.h.e.jdbc.spi.SqlExceptionHelper.logExceptions - SQL Error: 0, SQLState: 23505
06-04-2022 12:11:58.107 [http-nio-8080-exec-6] ERROR o.h.e.jdbc.spi.SqlExceptionHelper.logExceptions - ERROR: duplicate key value violates unique constraint "item_external_ids_identifier_service_code_identifier_item_i_key"
Detail: Key (identifier_service_code, identifier, item_id)=(GitHub, test/test, 40766) already exists.
06-04-2022 12:11:58.110 [http-nio-8080-exec-6] ERROR e.s.m.c.MarketplaceExceptionHandler.handleServerError - Runtime exception
org.springframework.dao.DataIntegrityViolationException: 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
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:298)
As the same workflow works like a charm if you don't save a draft but immediately publish the item, I suspect that publishing the draft item is done in a way so that it breaks the mentioned constraint.
@ekalata Could you look into this issue? It happend until now not that often, but as it is easy to initiate we need a bugfix for this.
Informing @lbarbot (already having this issue last week - thanks for reporting, it helped me to reconstruct the problem) and @matej.durco