Skip to content

Commit

Permalink
Fix failing tests #1066
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jun 3, 2024
1 parent d447438 commit 0a2e114
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 10 additions & 4 deletions scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
),
)


Expand Down
5 changes: 3 additions & 2 deletions scanpipe/tests/pipes/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 0a2e114

Please sign in to comment.