Skip to content

DiscoveredPackage matching query does not exist. #448

Description

@tdruez

Input: https://github.com/ballerina-platform/ballerina-lang/archive/refs/tags/v1.2.29.tar.gz
Pipeline: scan_package

DiscoveredPackage matching query does not exist.

Traceback:
  File "/app/scanpipe/pipelines/__init__.py", line 115, in execute
    step(self)
  File "/app/scanpipe/pipelines/scan_package.py", line 119, in build_inventory_from_scan
    scancode.create_inventory_from_scan(self.project, self.scan_output_location)
  File "/app/scanpipe/pipes/scancode.py", line 504, in create_inventory_from_scan
    create_codebase_resources(project, scanned_codebase)
  File "/app/scanpipe/pipes/scancode.py", line 398, in create_codebase_resources
    package = DiscoveredPackage.objects.get(package_uid=package_uid)
  File "/usr/local/lib/python3.9/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 496, in get
    raise self.model.DoesNotExist(

The culprit is the for_packages attribute on the codebase/ballerina-lang-1.2.29/tool-plugins/theia/yarn.lock resource that returns a list containing a None value as the package_uid, for_packages == [None].
None cannot be matched in the DB thus the model.DoesNotExist exception.

from commoncode.resource import VirtualCodebase
scanned_codebase = VirtualCodebase("scancode-2022-06-15-04-55-57.json")
resource = scanned_codebase.get_resource('codebase/ballerina-lang-1.2.29/tool-plugins/theia/yarn.lock')
resource.for_packages  # -> [None]
  1. This is likely an issue in the way the for_packages value is generated and needs to be fixed.
  2. The package QuerySet is not scoped with the current project in create_codebase_resources in https://github.com/nexB/scancode.io/blob/main/scanpipe/pipes/scancode.py#L398
  3. The package_uid field is not enforced to be unique in a project, also it is not indexed at the moment and it should as the code now heavily relies on it to fetch DiscoveredPackage instances https://github.com/nexB/scancode.io/blob/main/scanpipe/models.py#L1729

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions