From add21342744d474defaf8c13b94d12c64449903b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Fern=C3=A1ndez=20Poyatos?= Date: Sat, 30 Nov 2024 19:25:29 +0100 Subject: [PATCH] fix(overview): retrieve aggregated findings from completed scans (#5975) --- api/src/backend/api/v1/views.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/api/src/backend/api/v1/views.py b/api/src/backend/api/v1/views.py index a72f617d142..d9b36af945f 100644 --- a/api/src/backend/api/v1/views.py +++ b/api/src/backend/api/v1/views.py @@ -65,6 +65,7 @@ Scan, ScanSummary, SeverityChoices, + StateChoices, StatusChoices, Task, User, @@ -76,8 +77,8 @@ from api.v1.serializers import ( ComplianceOverviewFullSerializer, ComplianceOverviewSerializer, - FindingSerializer, FindingDynamicFilterSerializer, + FindingSerializer, InvitationAcceptSerializer, InvitationCreateSerializer, InvitationSerializer, @@ -1480,7 +1481,9 @@ def findings(self, request): filtered_queryset = self.filter_queryset(queryset) latest_scan_subquery = ( - Scan.objects.filter(provider_id=OuterRef("scan__provider_id")) + Scan.objects.filter( + state=StateChoices.COMPLETED, provider_id=OuterRef("scan__provider_id") + ) .order_by("-id") .values("id")[:1] ) @@ -1520,7 +1523,9 @@ def findings_severity(self, request): filtered_queryset = self.filter_queryset(queryset) latest_scan_subquery = ( - Scan.objects.filter(provider_id=OuterRef("scan__provider_id")) + Scan.objects.filter( + state=StateChoices.COMPLETED, provider_id=OuterRef("scan__provider_id") + ) .order_by("-id") .values("id")[:1] )