Skip to content

expose severities inside the affected by packages - #1799

Open
unibik wants to merge 3 commits into
aboutcode-org:mainfrom
unibik:expose-severities-in-apiv2
Open

expose severities inside the affected by packages #1799
unibik wants to merge 3 commits into
aboutcode-org:mainfrom
unibik:expose-severities-in-apiv2

Conversation

@unibik

@unibik unibik commented Mar 7, 2025

Copy link
Copy Markdown

fix: #1669
Added severities field in affected_by_vulnerabilities, and also updated test files. because of adding severities in apiv2 , test cases are failing due to Query count mismatch and Assertion errors in api response
I got no test fails after changing the testing files in my local machine ."If @keshav-space and @pombredanne suggest any alternative approaches to solving this issue, I am happy to consider and implement their perspectives."
Here is the result:
image
let me know is the output is in correct order.
Thank You

@unibik unibik changed the title expose severities inside the affected by packages fix: #1669 expose severities inside the affected by packages Mar 7, 2025

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Here is some feedback!

"""
url = reverse("package-v2-list")
with self.assertNumQueries(32):
with self.assertNumQueries(33):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to avoid the extra query?

@unibik unibik Mar 7, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes , i had tested select_related(), but it didn't worked .
I can investigate further to see if there is a for it . Let me know if you have any suggestions on alternative approach , which means alot to me . thank you

Comment thread vulnerabilities/tests/test_api_v2.py Outdated
"VCID-1234": {
"code_fixes": [],
"vulnerability_id": "VCID-1234",
"severities": [],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a new test that effectively return severities?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, fine ! i will add a test case where a vulnerability has severities and ensure that the API correctly returns them in the response. I'll update the PR once it's ready.

Comment thread vulnerabilities/api_v2.py
Prefetch(
"affected_by_vulnerabilities",
queryset=Vulnerability.objects.prefetch_related("fixed_by_packages"),
queryset=Vulnerability.objects.prefetch_related("fixed_by_packages","severities"),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really the way to send both to the same attribute below?

@unibik unibik Mar 7, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified that severities and fixed_by_packages are sent separately in the API response. Also, I tested removing severities from prefetch_related(), and the response remained the same, confirming that explicit prefetching was unnecessary. So in further changes i will remove severities .
Let me know if you have any further suggestions.
Thank you for spending your time on reviewing the changes i made and giving feedback..!!

Signed-off-by: Arshad <arshad.chotu10@gmail.com>
@unibik
unibik requested a review from pombredanne March 19, 2025 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose severity from AffectedByPackageRelatedVulnerability in APIv2

2 participants