digitalfabrik / entitlementcard

App for 'Digitale Berechtigungskarten', generally benefit card for volunteers or socially vulnerable groups in Germany. App for Android & iOS + Backend + Administration Web Portal – 100% Open Source.
MIT License
36 stars 3 forks source link

Fix regions key violation on createOrUpdateRegion #1601

Open f1sh1918 opened 2 months ago

f1sh1918 commented 2 months ago

Is your feature request related to a problem? Please describe. When starting the backend service on current main we are facing some constraint violation issue for the nuernberg region

Aug 27 13:38:42 entitlementcard-test.tuerantuer.org backend[819143]: [main] INFO Exposed - Preparing alter table statements took 632ms
Aug 27 13:38:42 entitlementcard-test.tuerantuer.org backend[819143]: [main] INFO Exposed - Checking mapping consistence took 223ms
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]: [main] WARN Exposed - Transaction attempt #0 failed: java.sql.BatchUpdateException: Batch entry 0 INSERT INTO regions ("activatedForApplicatio>
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]: RETURNING * was aborted: ERROR: duplicate key value violates unique constraint "regions_pkey"
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:   Detail: Key (id)=(94) already exists.  Call getNextException to see other errors in the batch.. Statement(s): INSERT INTO regions ("activate>
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]: org.jetbrains.exposed.exceptions.ExposedSQLException: java.sql.BatchUpdateException: Batch entry 0 INSERT INTO regions ("activatedForApplicati>
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]: RETURNING * was aborted: ERROR: duplicate key value violates unique constraint "regions_pkey"
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:   Detail: Key (id)=(94) already exists.  Call getNextException to see other errors in the batch.
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]: SQL: [INSERT INTO regions ("activatedForApplication", "activatedForCardConfirmationMail", "name", prefix, "projectId", "regionIdentifier", web>
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed_core(Statement.kt:65)
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:158)
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:144)
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.sql.statements.Statement.execute(Statement.kt:28)
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.sql.QueriesKt.executeBatch(Queries.kt:207)
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.sql.QueriesKt.batchInsert(Queries.kt:106)
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.sql.QueriesKt.batchInsert(Queries.kt:92)
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.sql.QueriesKt.batchInsert$default(Queries.kt:87)
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.dao.EntityCache$flushInserts$ids$1.invoke(EntityCache.kt:183)
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.dao.EntityCache$flushInserts$ids$1.invoke(EntityCache.kt:182)
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.dao.EntityLifecycleInterceptorKt.executeAsPartOfEntityLifecycle(EntityLifecycleInterceptor.kt:18)
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.dao.EntityCache.flushInserts$exposed_dao(EntityCache.kt:182)
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.dao.EntityCache.flush(EntityCache.kt:137)
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.dao.EntityCache.flush(EntityCache.kt:106)
Aug 27 13:38:43 entitlementcard-test.tuerantuer.org backend[819143]:         at org.jetbrains.exposed.dao.EntityCacheKt.flushCache(EntityCache.kt:242)

Describe the solution you'd like

f1sh1918 commented 2 months ago

After some restarting it was gone. Maybe related to #1602

ztefanie commented 2 months ago

Cannot reproduce

ztefanie commented 1 month ago

I just had a look at this and could not reproduce this. I think for further investigation we need a database dump ideally before and after the operation.