Duplicate Key Error When Using New API Key Button
Current Behavior
Creating a new API key in Dependency-Track fails with a unique constraint violation on the APIKEY table. This issue occurs when using the “New API Key” function in the UI, regardless of whether:
- The team already has an existing API key, or
- The team does not already have an API key
In both scenarios, the operation results in an unhandled exception, with the following error:
Insert of object "alpine.model.ApiKey@64a227e0" using statement: INSERT INTO "APIKEY" ("COMMENT","CREATED","IS_LEGACY","LAST_USED","PUBLIC_ID","SECRET_HASH") VALUES (?,?,?,?,?,?) failed: ERROR: duplicate key value violates unique constraint "APIKEY_IDX" Detail: Key ("APIKEY")=() already exists.
Steps to Reproduce
- Go to Administration > Access Management > Teams
- Select a Team
- Select New API key
- Server Error (500) is displayed
Expected Behavior
A new API key should get displayed in the UI
Dependency-Track Frontend Version
4.13.2
Browser
Microsoft Edge
Browser Version
Version 137.0.3296.52 (Official build) (arm64)
Operating System
macOS
Checklist
- [x] I have read and understand the contributing guidelines
- [x] I have checked the existing issues for whether this defect was already reported
The APIKEY column should no longer exist past the v4.13.0 upgrade:
https://github.com/DependencyTrack/dependency-track/blob/6e3b0aae13fb415225ea98fb6eb3ead39ebdea19/src/main/java/org/dependencytrack/upgrade/v4130/v4130_1Updater.java#L171-L175
Did you upgrade from a SNAPSHOT version?
We deployed using the official Helm charts, starting with version 0.22.0 (Dependency-Track 4.12.1), and are currently running version 0.33.0 (Dependency-Track 4.13.2). During the upgrade path, we applied most of the intermediate Helm chart versions.
Before I attempt to re-trigger the schema upgrade, is there anything specific I should verify that could help understand why it this happened?
Resolved by manually re-triggering part of the schema migration. Potentially related to DependencyTrack issue #4652, even though we never used a snapshot build.
What I had to do in our case was DELETE FROM "INSTALLEDUPGRADES" WHERE "UPGRADECLASS" = 'org.dependencytrack.upgrade.v4130.v4130_1Updater'; and then delete the api-server pod.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.