DependencyTrack / dependency-track

Dependency-Track is an intelligent Component Analysis platform that allows organizations to identify and reduce risk in the software supply chain.
https://dependencytrack.org/
Apache License 2.0
2.63k stars 558 forks source link

Project deletion causes DB table DEPENDENCYMETRICS constraint DEPENDENCYMETRICS_FK1 violation #2981

Open hostalp opened 1 year ago

hostalp commented 1 year ago

Current Behavior

2023-08-24 10:03:14,578 [] WARN [DataNucleus.Persistence] Delete of object with id "org.dependencytrack.model.Component:561" using statement "DELETE FROM "COMPONENT" WHERE "ID"=?" failed : ERROR: update or delete on table "COMPONENT" violates foreign key constraint "DEPENDENCYMETRICS_FK1" on table "DEPENDENCYMETRICS"
  Detail: Key (ID)=(561) is still referenced from table "DEPENDENCYMETRICS".
2023-08-24 10:03:14,579 [] ERROR [alpine.server.resources.GlobalExceptionHandler] Uncaught internal server error
javax.jdo.JDOUserException: One or more instances could not be deleted
        at org.datanucleus.api.jdo.JDOAdapter.getJDOExceptionForNucleusException(JDOAdapter.java:688)
        at org.datanucleus.api.jdo.JDOQuery.deletePersistentInternal(JDOQuery.java:530)
        at org.datanucleus.api.jdo.JDOQuery.deletePersistentAll(JDOQuery.java:486)
        at org.dependencytrack.persistence.ComponentQueryManager.deleteComponents(ComponentQueryManager.java:385)
        at org.dependencytrack.persistence.QueryManager.deleteComponents(QueryManager.java:528)
        at org.dependencytrack.persistence.ProjectQueryManager.recursivelyDelete(ProjectQueryManager.java:680)
        at org.dependencytrack.persistence.QueryManager.recursivelyDelete(QueryManager.java:446)
        at org.dependencytrack.resources.v1.ProjectResource.deleteProject(ProjectResource.java:477)
        ...
Caused by: org.datanucleus.exceptions.NucleusDataStoreException: Delete of object with id "org.dependencytrack.model.Component:21" using statement "DELETE FROM "COMPONENT" WHERE "ID"=?" failed : ERROR: update or delete on table "COMPONENT" violates foreign key constraint "DEPENDENCYMETRICS_FK1" on table "DEPENDENCYMETRICS"
  Detail: Key (ID)=(21) is still referenced from table "DEPENDENCYMETRICS".
        at org.datanucleus.store.rdbms.request.DeleteRequest.execute(DeleteRequest.java:377)
        at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.deleteObjectFromTable(RDBMSPersistenceHandler.java:534)
        at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.deleteObject(RDBMSPersistenceHandler.java:506)
        at org.datanucleus.state.StateManagerImpl.internalDeletePersistent(StateManagerImpl.java:1260)
        at org.datanucleus.state.StateManagerImpl.deletePersistent(StateManagerImpl.java:5513)
        at org.datanucleus.ExecutionContextImpl.deleteObjectInternal(ExecutionContextImpl.java:2294)
        at org.datanucleus.ExecutionContextImpl.deleteObjectWork(ExecutionContextImpl.java:2220)
        at org.datanucleus.ExecutionContextImpl.deleteObjects(ExecutionContextImpl.java:2116)
        at org.datanucleus.store.query.Query.performDeletePersistentAll(Query.java:2293)
        at org.datanucleus.store.query.AbstractJavaQuery.performDeletePersistentAll(AbstractJavaQuery.java:113)
        at org.datanucleus.store.query.Query.deletePersistentAll(Query.java:2245)
        at org.datanucleus.store.query.Query.deletePersistentAll(Query.java:2202)
        at org.datanucleus.api.jdo.JDOQuery.deletePersistentInternal(JDOQuery.java:508)
        ... 75 common frames omitted
Caused by: org.postgresql.util.PSQLException: ERROR: update or delete on table "COMPONENT" violates foreign key constraint "DEPENDENCYMETRICS_FK1" on table "DEPENDENCYMETRICS"
  Detail: Key (ID)=(21) is still referenced from table "DEPENDENCYMETRICS".
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2676)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2366)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:356)
        at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:496)
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:413)
        at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:190)
        at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:152)
        at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
        at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
        at org.datanucleus.store.rdbms.SQLController.executeStatementUpdate(SQLController.java:430)
        at org.datanucleus.store.rdbms.request.DeleteRequest.execute(DeleteRequest.java:338)
        ... 87 common frames omitted

Steps to Reproduce

User attempts to delete a project. The project appears to be deleted, however the dependency-track.log gets filled with a lot of ERROR: update or delete on table "COMPONENT" violates foreign key constraint "DEPENDENCYMETRICS_FK1" on table "DEPENDENCYMETRICS" Detail: Key (ID)=(561) is still referenced from table "DEPENDENCYMETRICS". exceptions.

Expected Behavior

The deletion process should run cleanly.

Dependency-Track Version

4.8.2

Dependency-Track Distribution

Container Image

Database Server

PostgreSQL

Database Server Version

12.13

Browser

Google Chrome

Checklist

mum-viadee commented 4 months ago

We currently have the same problems. To delete old projects, we have to delete the referenced records manually from the DEPENDENCYMETRICS table. It doesn't feel right, but is the only way to get rid of a few old projects.

Any progress on this issue since august 2023???