From 0a2e114e1faae24406e939d89f4c37beafa7c4bd Mon Sep 17 00:00:00 2001 From: tdruez Date: Mon, 3 Jun 2024 17:15:19 +0400 Subject: [PATCH] Fix failing tests #1066 Signed-off-by: tdruez --- scanpipe/models.py | 14 ++++++++++---- scanpipe/tests/pipes/test_output.py | 5 +++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/scanpipe/models.py b/scanpipe/models.py index 9407e2e22..3fa0b4bcb 100644 --- a/scanpipe/models.py +++ b/scanpipe/models.py @@ -3339,11 +3339,17 @@ def prefetch_for_serializer(self): `DiscoveredDependencySerializer`. Only the fields required by the serializer are fetched on the relations. """ - manager = DiscoveredPackage.objects return self.prefetch_related( - Prefetch("for_package", queryset=manager.only("package_uid")), - Prefetch("resolved_to_package", queryset=manager.only("package_uid")), - Prefetch("datafile_resource", queryset=manager.only("path")), + Prefetch( + "for_package", queryset=DiscoveredPackage.objects.only("package_uid") + ), + Prefetch( + "resolved_to_package", + queryset=DiscoveredPackage.objects.only("package_uid"), + ), + Prefetch( + "datafile_resource", queryset=CodebaseResource.objects.only("path") + ), ) diff --git a/scanpipe/tests/pipes/test_output.py b/scanpipe/tests/pipes/test_output.py index 664c82a8c..471d56c1b 100644 --- a/scanpipe/tests/pipes/test_output.py +++ b/scanpipe/tests/pipes/test_output.py @@ -294,7 +294,8 @@ def test_scanpipe_pipes_outputs_get_cyclonedx_bom_dependency_tree(self): make_dependency(project, for_package=a, resolved_to_package=b) make_dependency(project, for_package=b, resolved_to_package=c) - output_file = output.to_cyclonedx(project=project) + with self.assertNumQueries(2): + output_file = output.to_cyclonedx(project=project) results_json = json.loads(output_file.read_text()) expected = [ @@ -455,7 +456,7 @@ def test_scanpipe_pipes_outputs_to_attribution(self): package_data["notice_text"] = "Notice text" pipes.update_or_create_package(project, package_data) - with self.assertNumQueries(1): + with self.assertNumQueries(2): output_file = output.to_attribution(project=project) expected_file = self.data_path / "outputs" / "expected_attribution.html"