-
-
Notifications
You must be signed in to change notification settings - Fork 610
Description
I'm getting an error when trying to create a PackageData object: https://github.com/nexB/purldb/blob/purldb-updates-sctk-32/minecode/mappers/pypi.py#L135
Traceback (most recent call last):
File "/home/jono/nexb/src/purldb/minecode/tests/test_pypi.py", line 203, in test_pypi_map
packages = [p.to_dict() for p in packages]
File "/home/jono/nexb/src/purldb/minecode/tests/test_pypi.py", line 203, in <listcomp>
packages = [p.to_dict() for p in packages]
File "/home/jono/nexb/src/purldb/minecode/mappers/pypi.py", line 134, in build_packages
package = scan_models.PackageData(
File "<attrs generated init packagedcode.models.PackageData>", line 65, in __init__
self.__attrs_post_init__()
File "/home/jono/nexb/src/purldb/venv/lib/python3.10/site-packages/packagedcode/models.py", line 721, in __attrs_post_init__
self.populate_license_fields()
File "/home/jono/nexb/src/purldb/venv/lib/python3.10/site-packages/packagedcode/models.py", line 768, in populate_license_fields
self.get_license_detections_and_expression()
File "/home/jono/nexb/src/purldb/venv/lib/python3.10/site-packages/packagedcode/models.py", line 874, in get_license_detections_and_expression
default_relation_license=get_default_relation_license(
File "/home/jono/nexb/src/purldb/venv/lib/python3.10/site-packages/packagedcode/models.py", line 882, in get_default_relation_license
handler = HANDLER_BY_DATASOURCE_ID[datasource_id]
KeyError: None
This is because I am creating a Package that does not have a handler in packagedcode for it. self.populate_license_fields()
is being called whenever the PackageData is instantiated. self.populate_license_fields()
calls a few functions until it gets to get_default_relation_license
, where it is looking for a particular handle to handle a package type. Since there is no handler for the type of package I am creating, I encounter this exception.
The workaround suggested by @AyanSinhaMahapatra is to modify https://github.com/nexB/scancode-toolkit/blob/develop/src/packagedcode/models.py#LL874C13-L874C37 to look like:
if self.datasource_id:
default_relation_license=get_default_relation_license(
datasource_id=self.datasource_id,
)
else:
default_relation_license = "AND"
return get_license_detections_and_expression(
extracted_license_statement=self.extracted_license_statement,
default_relation_license=default_relation_license
)