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.69k stars 578 forks source link

An inactive Parent cannot be selected as parent #2935

Closed zeenmc closed 11 months ago

zeenmc commented 1 year ago

Current Behavior

Hello Team :)

I am having issues to create child project, as I am getting error from the tittle. I am feeling this is a bug as I am able to reproduce multiple times. Our DT is 4.8.2 ,and we are using MS SQL Server.

2023-08-04T15:41:44.748118564Z: [INFO]  2023-08-04 15:41:44,747 INFO [ProjectResource] Project test-active10 created by TdCK****ST0B
2023-08-04T15:42:08.231296303Z: [INFO]  2023-08-04 15:42:08,231 ERROR [GlobalExceptionHandler] Uncaught internal server error
2023-08-04T15:42:08.231350404Z: [INFO]  java.lang.IllegalArgumentException: An inactive Parent cannot be selected as parent
#Parent project creation :

curl --verbose -X PUT "https://dt-api.azurewebsites.net/api/v1/project" \
-H 'Content-Type: application/json' \
-H 'X-Api-Key: TdCKerfddgdn7zsLfFST0B' \
-d '{"name": "management-mfe"}' \
-d '{"active": "true"}'

After I created project via curl command (idea is to have whole this proccess in CICD pipelines in Azure DevOps), In UI, I ass project is active

and If I try to push child project:
curl --verbose -X POST "https://dt-api.azurewebsites.net/api/v1/bom" \
-H 'Content-Type: multipart/form-data' \
-H 'X-Api-Key: TdCKerfddgdn7zsLfFST0B' \
-F "classifier=Application" \
-F "projectName=management-mfe" \
-F "autoCreate=true" \
-F "projectVersion=10" \
-F "parentName=management-mfe" \
-F "bom=@/Users/SCN1BG/Desktop/services/frontend/user-management-mfe/bom-lokal.json"

I will get error from title, as I said, but if I go to UI, in Project Details which I created, and disable project, save changes, again enable project, and wait for a few seconds, I will be able to create child project without any errors.

Where is log when I disable/enable just created project

2023-08-04T15:42:43.062880058Z: [INFO]  2023-08-04 15:42:43,062 INFO [ProjectResource] Project test-active10 updated by admin
2023-08-04T15:42:54.218621500Z: [INFO]  2023-08-04 15:42:54,218 INFO [ProjectResource] Project test-active10 updated by admin

Any ideas how to resolve this issue ? Ned.

Steps to Reproduce

1.Create project via cURL command

  1. Try to create child project also via cURL
  2. will not works, error will be shown
  3. Open project Project Details, disable project, update, open again Project Details, update project
  4. try to create child project via cURL

Expected Behavior

After we create parent project, without any issues we need to be able to create child project.

Dependency-Track Version

4.8.2

Dependency-Track Distribution

Container Image

Database Server

Microsoft SQL Server

Database Server Version

No response

Browser

Google Chrome

Checklist

antoinbo commented 1 year ago

Hello @zeenmc, Are you sure of the project names in the cURL commands?

  1. First command you create the project test-prod10.
  2. Second command you create the project user-management-mfe-10 with parent test-active10 (do not match project in first request).
zeenmc commented 1 year ago

Hello @antoinbo, that is my mistake, but yes I am sure, in my visual code I have many examples what I tested, tried to fix issue. On the end I did manually and will check later on, in some another verision.

Behaviour is correct.

Create project via cURL, disable, enable, and after that will be possible to create child project.

jeremytbrun commented 12 months ago

Any progress on this? I am just now encountering a similar issue. I am creating a parent project via the API successfully and then immediately trying to create a child project via the API specifying the parent UUID. I am getting the same An inactive Parent cannot be selected as parent error as indicated above. If I go to the UI and disable the parent project then enable the parent project DT will then allow me to specify it as a parent. I'm on DT v4.9.1 w/ MS SQL DB.

jeremytbrun commented 12 months ago

Here is a repro of the issue using PowerShell v7.3.9

> $Result = Invoke-RestMethod -Method PUT -Uri $Uri -Headers $Headers -Body (@{name='parent';'version'='1.0.0'} | ConvertTo-Json)
> $Result

name       : parent
version    : 1.0.0
classifier : APPLICATION
uuid       : 34e1fd19-3fb7-4960-9be1-5f112bdbb901
properties : {}
tags       : {}
active     : True

> Invoke-RestMethod -Method PUT -Uri $Uri -Headers $Headers -Body (@{name='child';'version'='2.0.0';parent=@{uuid=$Result.uuid}} | ConvertTo-Json)
Invoke-RestMethod: An inactive Parent cannot be selected as parent
willienel commented 11 months ago

When using the API to create a project, specifically the PUT variant, you need to currently specify the "active" field in the payload otherwise it will be null and cause the error.

The method in question is here:

https://github.com/DependencyTrack/dependency-track/blob/09e8111096899c0950ece087ab739095f1f7636b/src/main/java/org/dependencytrack/resources/v1/ProjectResource.java#L229

This can either be fixed by adding something similar to what was done for the application classifier:

if (jsonProject.isActive() == null) {
    jsonProject.setActive(Boolean.TRUE);
}

Or by setting a default "active" value for all newly created projects on the persistence level.

jeremytbrun commented 11 months ago

When using the API to create a project, specifically the PUT variant, you need to currently specify the "active" field in the payload otherwise it will be null and cause the error.

The method in question is here:

https://github.com/DependencyTrack/dependency-track/blob/09e8111096899c0950ece087ab739095f1f7636b/src/main/java/org/dependencytrack/resources/v1/ProjectResource.java#L229

This can either be fixed by adding something similar to what was done for the application classifier:

if (jsonProject.isActive() == null) {
    jsonProject.setActive(Boolean.TRUE);
}

Or by setting a default "active" value for all newly created projects on the persistence level.

Confirmed explicitly setting the active value resolves the issue. Thanks!

github-actions[bot] commented 10 months ago

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.