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

Cannot update a project with new tag names (that are not used already on the platform) #4755

Open
2 tasks done
dan-caprioara opened this issue Mar 13, 2025 · 0 comments
Open
2 tasks done
Labels
defect Something isn't working in triage

Comments

@dan-caprioara
Copy link

Current Behavior

If a tag was already attached to another project(tag T1 on project X), you can use the API to associate the tag T1 on project Y as well. But if you use the API to put a new tag T2 on project Y, it will fail with: "A tag with name T2 does not exist."

Steps to Reproduce

  1. Use the Rest API to tag a project with a brand new tag name:
     @Path("/{name}/project")
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
     @Operation(
             summary = "Tags one or more projects.",
             description = "<p>Requires permission <strong>PORTFOLIO_MANAGEMENT</strong></p>"
     )````, it will call `org.dependencytrack.resources.v1.TagResource.tagProjects(String, Set<String>)`
    
  2. An eror is obtained: "A tag with name T2 does not exist.""

Expected Behavior

The tag should be created automatically, persisted, and associated to the project, OR at least a REST API to properly create a tag should be provided. (By the way, please update the API descriptors, it looks like the API documentation is not updated)
org.dependencytrack.persistence.TagQueryManager.tagProjects(String, Collection)

        runInTransaction(() -> {
            final Tag tag = getTagByName(tagName);
            if (tag == null) {
              // TODO - CREATE HERE THE TAG,
                throw new NoSuchElementException("A tag with name %s does not exist".formatted(tagName));
            }

            final Query<Project> projectsQuery = pm.newQuery(Project.class);
            final var params = new HashMap<String, Object>(Map.of("uuids", projectUuids));
            preprocessACLs(projectsQuery, ":uuids.contains(uuid)", params, /* bypass */ false);
            projectsQuery.setNamedParameters(params);
            final List<Project> projects = executeAndCloseList(projectsQuery);

            for (final Project project : projects) {
                bind(project, List.of(tag), /* keepExisting */ true);
            }
        });
    }

Dependency-Track Version

4.12.6

Dependency-Track Distribution

Container Image

Database Server

PostgreSQL

Database Server Version

No response

Browser

Google Chrome

Checklist

@dan-caprioara dan-caprioara added defect Something isn't working in triage labels Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Something isn't working in triage
Projects
None yet
Development

No branches or pull requests

1 participant