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

Port : Fix REST endpoints for adding tags #1042

Merged
merged 4 commits into from
Feb 7, 2025

Conversation

sahibamittal
Copy link
Collaborator

@sahibamittal sahibamittal commented Jan 28, 2025

Description

Fixes REST endpoints for adding tags.

Addressed Issue

Ports DependencyTrack/dependency-track#4543
Port change DependencyTrack/hyades#1358

Checklist

  • I have read and understand the contributing guidelines
  • This PR fixes a defect, and I have provided tests to verify that the fix is effective
  • This PR implements an enhancement, and I have provided tests to verify that it works as intended
  • This PR introduces changes to the database model, and I have updated the migration changelog accordingly
  • This PR introduces new or alters existing behavior, and I have updated the documentation accordingly

@sahibamittal sahibamittal added defect Something isn't working v4-port PRs that were ported from the Dependency-Track v4.x code base labels Jan 28, 2025
@sahibamittal sahibamittal added this to the 5.6.0 milestone Jan 28, 2025
nscuro
nscuro previously approved these changes Jan 28, 2025
@nscuro
Copy link
Member

nscuro commented Feb 6, 2025

@sahibamittal The test is failing because this condition:

if (isUniqueConstraintViolation(e)) {
throw new ClientErrorException(Response
.status(Response.Status.CONFLICT)
.entity("A project with the specified name and version already exists.")
.build());
}

can no longer happen in this location.

The unique constraint violation originating from the database will only be thrown when the DB transaction commits.

Because the statement in question is also wrapped in a callInTransaction:

final Project updatedProject = qm.callInTransaction(() -> {

the transaction will only commit after that call completes, so technically here.

The solution is to wrap the outermost callInTransaction in a try-catch block, catching RuntimeException, and doing the isUniqueConstraintViolation check there.

I am not sure why that behavior changed in this particular PR though...

@sahibamittal
Copy link
Collaborator Author

@sahibamittal The test is failing because this condition:

if (isUniqueConstraintViolation(e)) {
throw new ClientErrorException(Response
.status(Response.Status.CONFLICT)
.entity("A project with the specified name and version already exists.")
.build());
}

can no longer happen in this location.

The unique constraint violation originating from the database will only be thrown when the DB transaction commits.

Because the statement in question is also wrapped in a callInTransaction:

final Project updatedProject = qm.callInTransaction(() -> {

the transaction will only commit after that call completes, so technically here.

The solution is to wrap the outermost callInTransaction in a try-catch block, catching RuntimeException, and doing the isUniqueConstraintViolation check there.

I am not sure why that behavior changed in this particular PR though...

Thanks for checking Niklas 👍🏼
I've moved RuntimeException outside but apart from isUniqueConstraintViolation it should throw exception as is else ClientErrorException being thrown inside will get caught here.

@sahibamittal sahibamittal requested a review from nscuro February 7, 2025 16:10
Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.00% (target: -1.00%) 89.36% (target: 70.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (6f4ed40) 22318 18502 82.90%
Head commit (e95dc31) 22330 (+12) 18513 (+11) 82.91% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#1042) 47 42 89.36%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

@nscuro nscuro merged commit 8ca5bae into main Feb 7, 2025
9 checks passed
@nscuro nscuro deleted the port-Fix-REST-endpoints-for-adding-tags branch February 7, 2025 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Something isn't working v4-port PRs that were ported from the Dependency-Track v4.x code base
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants