Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect API response from GET /api/v1/project/{id} following a specific sequence of API calls #3883

Closed
2 tasks done
michal-futurice opened this issue Jun 26, 2024 · 2 comments · Fixed by #3959
Closed
2 tasks done
Labels
defect Something isn't working p2 Non-critical bugs, and features that help organizations to identify and reduce risk size/S Small effort
Milestone

Comments

@michal-futurice
Copy link

Current Behavior

Dependency-Track returns an incorrect response body when creating and reading a project with a parent via the API with the following sequence of calls:

  1. PUT /api/v1/project to create a parent project (that itself has no parent)
  2. PUT /api/v1/project to create a child project (that has the project from step 1 as its parent)
  3. GET /api/v1/project/{parentId}
  4. GET /api/v1/project/{childId}

In this sequence the response from step (3) correctly identifies the child in the children field (responses prettified for readibility):

{
  "name": "test-parent-project",
  "classifier": "APPLICATION",
  "uuid": "75895014-82c1-466b-98ea-100514a587b2",
  "children": [
    {
      "name": "test-child-project",
      "classifier": "APPLICATION",
      "uuid": "4c5fa8d4-6244-4d25-bf71-ead6c820ebd1",
      "parent": {
        "name": "test-parent-project",
        "uuid": "75895014-82c1-466b-98ea-100514a587b2"
      },
      "active": true
    }
  ],
  "properties": [],
  "tags": [],
  "active": true,
  "versions": [
    {
      "uuid": "75895014-82c1-466b-98ea-100514a587b2"
    }
  ]
}

But the response from (4) contains a malformed field "parent":{} instead of a reference to the parent:

{
  "name": "test-child-project",
  "classifier": "APPLICATION",
  "uuid": "4c5fa8d4-6244-4d25-bf71-ead6c820ebd1",
  "parent": {},
  "children": [],
  "properties": [],
  "tags": [],
  "active": true,
  "versions": [
    {
      "uuid": "4c5fa8d4-6244-4d25-bf71-ead6c820ebd1"
    }
  ]
}

The ordering of calls is important. Exchanging the order of steps (3) and (4) (i.e. getting the child after its created before getting its parent) fixes this problem, apparently for all subsequent calls like (4).

We've also noticed another effect: the GET parent project response has no parent field at all before the child is created. But after the child is created the response contains a correctly formed parent field pointing back to the parent. We're not sure whether this is a second defect (and which of the two ways is correct), or by design.

Steps to Reproduce

  1. The attached script can be reviewed and then used to (hopefully) replicate the problem and test various call orderings.

This was tested on a dockerized DT started from a docker compose file consistent with https://dependencytrack.org/docker-compose.yml (no changes to the configuration of those two containers).

cause-bug.sh.gz

Expected Behavior

Responses from GET /api/v1/project/{projectId} should correctly identify the parent project or lack thereof regardless of API call order.

Dependency-Track Version

4.11.4

Dependency-Track Distribution

Container Image

Database Server

N/A

Database Server Version

No response

Browser

N/A

Checklist

@michal-futurice michal-futurice added defect Something isn't working in triage labels Jun 26, 2024
@nscuro nscuro added p2 Non-critical bugs, and features that help organizations to identify and reduce risk size/S Small effort and removed in triage labels Jul 9, 2024
@nscuro
Copy link
Member

nscuro commented Jul 9, 2024

Thanks for the detailed reproduction steps! I was able to reproduce this with v4.11.x, but not with v4.12.0-SNAPSHOT (current master).

I suspect that this change in Alpine 3.0.0 (which is what DT v4.12 is based on) had something to do with it.

Previously, objects were reloaded from the database immediately after they've been persisted. That means that the object instance being returned to the API did not necessarily have the same fields loaded, that the persisted instance had.

I'll add a regression test case for this specific scenario.

@nscuro nscuro added this to the 4.12 milestone Jul 9, 2024
@nscuro nscuro closed this as completed in e11f73c Jul 9, 2024
netomi pushed a commit to netomi/dependency-track that referenced this issue Aug 8, 2024
Copy link
Contributor

github-actions bot commented Aug 9, 2024

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 github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
defect Something isn't working p2 Non-critical bugs, and features that help organizations to identify and reduce risk size/S Small effort
Projects
None yet
2 participants