-
-
Notifications
You must be signed in to change notification settings - Fork 536
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
Duplicate tag is created upon updating a project #1165
Comments
Can be reproduced with the following test package org.dependencytrack.resources.v1;
...
public class ProjectResourceTest extends ResourceTest {
...
@Test
public void updateProjectTagsTest()
{
var tags = Stream.of("tag1", "tag2").map(qm::createTag).collect(Collectors.toUnmodifiableList());
var p1 = qm.createProject("ABC", "Test project", "1.0", tags, null, null, true, false);
var jsonProject = new Project();
jsonProject.setUuid(p1.getUuid());
jsonProject.setName(p1.getName());
jsonProject.setVersion(p1.getVersion());
jsonProject.setTags(Stream.of("tag1", "tag2", "tag3").map(name ->
{
var t = new Tag();
t.setName(name);
return t;
}).collect(Collectors.toUnmodifiableList()));
// update the 1st time
Response response = target(V1_PROJECT)
.request()
.header(X_API_KEY, apiKey)
.post(Entity.entity(jsonProject, MediaType.APPLICATION_JSON));
Assert.assertEquals(200, response.getStatus(), 0);
JsonObject json = parseJsonObject(response);
Assert.assertNotNull(json);
Assert.assertEquals("ABC", json.getString("name"));
Assert.assertEquals("1.0", json.getString("version"));
Assert.assertFalse(json.containsKey("description"));
var jsonTags = json.getJsonArray("tags");
Assert.assertEquals(3, jsonTags.size());
Assert.assertEquals("tag1", jsonTags.get(0).asJsonObject().getString("name"));
Assert.assertEquals("tag2", jsonTags.get(1).asJsonObject().getString("name"));
Assert.assertEquals("tag3", jsonTags.get(2).asJsonObject().getString("name"));
// and repeat ... will fail. issue #1165
response = target(V1_PROJECT)
.request()
.header(X_API_KEY, apiKey)
.post(Entity.entity(jsonProject, MediaType.APPLICATION_JSON));
json = parseJsonObject(response);
jsonTags = json.getJsonArray("tags");
Assert.assertEquals(3, jsonTags.size());
Assert.assertEquals("tag1", jsonTags.get(0).asJsonObject().getString("name"));
Assert.assertEquals("tag2", jsonTags.get(1).asJsonObject().getString("name"));
Assert.assertEquals("tag3", jsonTags.get(2).asJsonObject().getString("name"));
}
} |
The issues seems to be this code here: dependency-track/src/main/java/org/dependencytrack/persistence/ProjectQueryManager.java Lines 628 to 631 in 1d6ce18
The tags are already associated with the projects through dependency-track/src/main/java/org/dependencytrack/persistence/ProjectQueryManager.java Line 628 in 1d6ce18
Afterwards, the project is added to the (new) tags again. dependency-track/src/main/java/org/dependencytrack/persistence/ProjectQueryManager.java Lines 628 to 631 in 1d6ce18
And after the commit dependency-track/src/main/java/org/dependencytrack/persistence/ProjectQueryManager.java Line 632 in 1d6ce18
the project has 6 tags instead of 3 with each tag twice. Will provide a PR to fix this. |
Add a project to the list of projects of a tag only if the list does not contain the project yet. fixes DependencyTrack#1165 Signed-off-by: Ronny Perinke <23166289+sephiroth-j@users.noreply.github.com>
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. |
Bug with
POST /v1/project
endpoint.Current Behavior:
Let's say you have already created a project with a specific tag
mytag
.If you will update a project with no changes, e.g. just send back values that are equal to previous, then you will get duplicates.
Steps to Reproduce:
Response:
Response:
By repeating (3) that will create tag duplicates. At the moment (after execution 3 commands above), you will get two double
mytag
tags on the same project.The same behaviour could be reproduced via UI. Just create a project. Go to project edit, add tag and click on "Update". And then again go to project edit ("View details" button) and just click "Update".
Expected Behavior:
I'm expecting to do not have duplicates.
Environment:
The text was updated successfully, but these errors were encountered: