Skip to content

HTTP 500 when converting a collection project back to a regular project, if the request body carries parent #7241

Closed

Description

@xavier-calland

Current Behavior

On 5.1.0 (PostgreSQL 18), POST /api/v1/project returns 500 Uncaught internal server error when a
request clears collectionLogic, sets a classifier, and carries a parent. The same request
without parent returns 200 — but the project then loses its parent, POST replacing the whole
resource. So a collection project cannot be turned back into a regular project while keeping its
parent.

ERROR [logger] Update of object with id "org.dependencytrack.model.Project:4734" using statement
"UPDATE "PROJECT" SET "CLASSIFIER"=? WHERE "ID"=?" failed :
org.postgresql.util.PSQLException: ERROR: new row for relation "PROJECT"
violates check constraint "PROJECT_COLLECTION_CLASSIFIER_check"

That constraint — CHECK (COLLECTION_LOGIC IS NULL OR CLASSIFIER IS NULL) — is intentional (V202605022031__init.sql#L886).
The problem is that ProjectQueryManager.updateProject lets the row transit through a state it
forbids:

  1. L262 sets the classifier on the persistent object, marking the field dirty.
  2. L291-L292 resolves the parent with a query. DataNucleus flushes dirty state before any query, emitting
    UPDATE "PROJECT" SET "CLASSIFIER"=? while COLLECTION_LOGIC still holds AGGREGATE_* — both
    columns non-null, constraint violated.
  3. L330, which clears COLLECTION_LOGIC, is never reached.

With no parent in the body, step 2 is replaced by setParent(null), which runs no query, so
nothing is flushed early and the single flush in persist(project) writes a consistent row.

The same hazard is already documented and guarded a few lines below for collectionTag (L315-L318); the parent lookup is not.

Clients cannot avoid this: omitting collectionLogic, sending it as null, and sending
classifier: null all fail identically, because the resource layer forces a non-null classifier
whenever collectionLogic is null (ProjectResource.java#L792-L796).

Steps to Reproduce

  1. Create a project parent-demo.
  2. Create a project child-demo version 1.0.0, with parent-demo as its parent.
  3. Edit child-demo: tick Collection project, choose Aggregate direct children, save.
    This succeeds — the UI clears the classifier by itself, as the constraint requires.
  4. Edit child-demo again: untick Collection project, pick any classifier, save.
    → 500, nothing is saved.

Step 4 fails because the form posts classifier, collectionLogic: null and parent in the same
payload (ProjectDetailsModal.vue).
It fails whether or not a classifier is picked, since the API substitutes APPLICATION for a null
one.

The same happens on a direct POST /api/v1/project with that payload. Dropping parent from it is
what isolates the cause — the request then returns 200, but the project loses its parent:

// POST /api/v1/project → 500
{"uuid":"<child>","name":"child-demo","version":"1.0.0","active":true,
 "classifier":"LIBRARY","parent":{"uuid":"<parent>"}}

// same, without "parent" → 200, and then: collectionLogic=null, classifier=LIBRARY, parent=null
{"uuid":"<child>","name":"child-demo","version":"1.0.0","active":true,
 "classifier":"LIBRARY"}

Expected Behavior

Step 4 should succeed, leaving child-demo with collectionLogic = null, the chosen classifier,
and its parent unchanged.

collectionLogic should be applied before any query that can flush dirty state. Moving the parent
resolution block (L286-L304) above the setClassifier call, or setting collectionLogic before the classifier, should suffice —
the same shape as the existing collectionTag guard. If the combination is meant to be rejected,
a 400/409 with a message would be preferable to an uncaught 500.

Dependency-Track Version

5.x

Browser

N/A

Checklist

Activity

  1. added
    defect
    on Sep 7, 2026
  2. added
    p2
    size/S
    and removed on Sep 15, 2026
  3. added this to the 5.1.1 milestone on Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectp2size/S

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions