Skip to content

Commit f677db2

Browse files
committed
Apply DISTINCT in the filter_run_status #1743
Signed-off-by: tdruez <[email protected]>
1 parent 25bf560 commit f677db2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

scanpipe/filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def filter_run_status(self, queryset, name, value):
446446
"""Filter by Run status using the `RunQuerySet` methods."""
447447
run_queryset_method = value
448448
run_queryset = getattr(Run.objects, run_queryset_method)()
449-
return queryset.filter(runs__in=run_queryset)
449+
return queryset.filter(runs__in=run_queryset).distinct()
450450

451451

452452
class JSONContainsFilter(django_filters.CharFilter):

scanpipe/tests/test_views.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ def test_scanpipe_views_project_list_state_of_filters_in_search_form(self):
151151
expected = '<input type="hidden" name="status" value="failed">'
152152
self.assertContains(response, expected, html=True)
153153

154+
def test_scanpipe_views_project_list_filter_by_status_distinct_results(self):
155+
url = reverse("project_list")
156+
pipeline1 = self.project1.add_pipeline(pipeline_name="scan_codebase")
157+
pipeline1.set_task_stopped()
158+
pipeline2 = self.project1.add_pipeline(pipeline_name="scan_codebase")
159+
pipeline2.set_task_stopped()
160+
161+
data = {"status": "failed"}
162+
response = self.client.get(url, data=data)
163+
self.assertEqual(1, len(response.context["object_list"]))
164+
154165
@mock.patch("scanpipe.views.ProjectListView.get_paginate_by")
155166
def test_scanpipe_views_project_list_filters_exclude_page(self, mock_paginate_by):
156167
url = reverse("project_list")

0 commit comments

Comments
 (0)