Skip to content

Commit 1dcb8f0

Browse files
committed
fix: Add weaknesses data in packages api endpoint
1 parent 432a7d4 commit 1dcb8f0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

vulnerabilities/api.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,24 @@ def get_vulnerabilities_for_a_package(self, package, fix) -> dict:
355355
"fixed_by_packages",
356356
queryset=fixed_packages,
357357
to_attr="filtered_fixed_packages",
358+
),
359+
Prefetch(
360+
"weaknesses",
361+
queryset=Weakness.objects.all(),
362+
to_attr="prefetched_weaknesses",
358363
)
359364
)
360-
return VulnSerializerRefsAndSummary(
365+
vulnerabilities_data = VulnSerializerRefsAndSummary(
361366
instance=qs,
362367
many=True,
363368
context={"request": self.context["request"]},
364369
).data
365370

371+
for vuln, vuln_instance in zip(vulnerabilities_data, qs):
372+
vuln["weaknesses"] = [weakness.to_dict() for weakness in vuln_instance.prefetched_weaknesses]
373+
374+
return vulnerabilities_data
375+
366376
def get_fixing_vulnerabilities(self, package) -> dict:
367377
"""
368378
Return a mapping of vulnerabilities fixed in the given `package`.

0 commit comments

Comments
 (0)