Skip to content

Commit 54ef9de

Browse files
authored
Merge pull request #180 from nexB/fix-filter-by-checksums
Fix filter by checksums
2 parents dfbc100 + 756629b commit 54ef9de

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

packagedb/api.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,11 @@ def filter_by_checksums(self, request, *args, **kwargs):
531531
This will return Packages whose sha1 or md5 matches those values.
532532
"""
533533
data = dict(request.data)
534+
534535
unsupported_fields = []
536+
supported_fields = ['md5', 'sha1', 'sha256', 'sha512', 'enhance_package_data']
535537
for field, value in data.items():
536-
if field not in ('md5', 'sha1', 'sha256', 'sha512', 'enhance_package_data'):
538+
if field not in supported_fields:
537539
unsupported_fields.append(field)
538540

539541
if unsupported_fields:
@@ -544,14 +546,21 @@ def filter_by_checksums(self, request, *args, **kwargs):
544546
return Response(response_data)
545547

546548
enhance_package_data = data.pop('enhance_package_data', False)
547-
q = Q()
549+
if not data:
550+
response_data = {
551+
'status': 'No values provided'
552+
}
553+
return Response(response_data)
554+
555+
lookups = Q()
548556
for field, value in data.items():
557+
value = value or []
549558
# We create this intermediate dictionary so we can modify the field
550559
# name to have __in at the end
551560
d = {f'{field}__in': value}
552-
q |= Q(**d)
561+
lookups |= Q(**d)
553562

554-
qs = Package.objects.filter(q)
563+
qs = Package.objects.filter(lookups)
555564
paginated_qs = self.paginate_queryset(qs)
556565
if enhance_package_data:
557566
serialized_package_data = [get_enhanced_package(package=package) for package in paginated_qs]
@@ -685,7 +694,7 @@ class PackageSetViewSet(viewsets.ReadOnlyModelViewSet):
685694
def get_resolved_purls(packages):
686695
"""
687696
Take a list of dict containing purl or version-less purl along with vers
688-
and return a list of resolved purls, a list of unsupported purls, and a
697+
and return a list of resolved purls, a list of unsupported purls, and a
689698
list of unsupported vers.
690699
"""
691700
unique_resolved_purls = set()
@@ -765,9 +774,9 @@ def get_all_versions(purl: PackageURL):
765774

766775
package_name = get_api_package_name(purl)
767776
versionAPI = get_version_fetcher(purl)
768-
777+
769778
if not package_name or not versionAPI:
770-
return
779+
return
771780

772781
all_versions = versionAPI().fetch(package_name)
773782
versionClass = VERSION_CLASS_BY_PACKAGE_TYPE.get(purl.type)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ install_requires =
5555
rubymarshal == 1.0.3
5656
scancode-toolkit[full] == 32.0.6
5757
urlpy == 0.5
58-
matchcode-toolkit == 1.1.1
58+
matchcode-toolkit >= 1.1.1
5959
univers == 30.10.0
6060
setup_requires = setuptools_scm[toml] >= 4
6161

0 commit comments

Comments
 (0)