dependency-track icon indicating copy to clipboard operation
dependency-track copied to clipboard

Duplicate Key Error When Using New API Key Button

Open shugg opened this issue 6 months ago • 2 comments

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

  1. Go to Administration > Access Management > Teams
  2. Select a Team
  3. Select New API key
  4. 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

shugg avatar Jun 06 '25 10:06 shugg

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?

nscuro avatar Jun 06 '25 10:06 nscuro

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?

shugg avatar Jun 10 '25 07:06 shugg

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.

shugg avatar Jul 14 '25 13:07 shugg

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.

github-actions[bot] avatar Aug 14 '25 10:08 github-actions[bot]