Skip to content

Commit

Permalink
Fix failing test #1519
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jan 13, 2025
1 parent 8719906 commit 1013766
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions scanpipe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3071,22 +3071,9 @@ def vulnerable(self):
return self.filter(~Q(affected_by_vulnerabilities__in=EMPTY_VALUES))


class OnlyPackageURLFieldsQuerySetMixin:
def only_package_url_fields(self, extra=None):
"""
Only select and return the UUID and PURL fields.
Minimum requirements to render a Package link in the UI.
"""
if not extra:
extra = []

return self.only("pk", *PACKAGE_URL_FIELDS, *extra)


class DiscoveredPackageQuerySet(
VulnerabilityQuerySetMixin,
PackageURLQuerySetMixin,
OnlyPackageURLFieldsQuerySetMixin,
ComplianceAlertQuerySetMixin,
ProjectRelatedQuerySet,
):
Expand All @@ -3099,6 +3086,16 @@ def with_resources_count(self):
)
return self.annotate(resources_count=count_subquery)

def only_package_url_fields(self, extra=None):
"""
Only select and return the UUID and PURL fields.
Minimum requirements to render a Package link in the UI.
"""
if not extra:
extra = []

return self.only("uuid", *PACKAGE_URL_FIELDS, *extra)

def filter(self, *args, **kwargs):
"""Add support for using ``package_url`` as a field lookup."""
if purl_str := kwargs.pop("package_url", None):
Expand Down Expand Up @@ -3678,7 +3675,6 @@ def as_cyclonedx(self):

class DiscoveredDependencyQuerySet(
PackageURLQuerySetMixin,
OnlyPackageURLFieldsQuerySetMixin,
VulnerabilityQuerySetMixin,
ProjectRelatedQuerySet,
):
Expand All @@ -3701,6 +3697,16 @@ def prefetch_for_serializer(self):
),
)

def only_package_url_fields(self, extra=None):
"""
Only select and return the UUID and PURL fields.
Minimum requirements to render a Package link in the UI.
"""
if not extra:
extra = []

return self.only("dependency_uid", *PACKAGE_URL_FIELDS, *extra)


class DiscoveredDependency(
ProjectRelatedModel,
Expand Down

0 comments on commit 1013766

Please sign in to comment.