From dedccc55806312e896154256e8156fa418faf277 Mon Sep 17 00:00:00 2001 From: Ayan Sinha Mahapatra Date: Tue, 5 Nov 2024 19:32:02 +0530 Subject: [PATCH] Fix bug at following package license references Reference: https://github.com/aboutcode-org/scancode-toolkit/issues/3969 Signed-off-by: Ayan Sinha Mahapatra --- src/licensedcode/plugin_license.py | 7 +++++-- src/packagedcode/licensing.py | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/licensedcode/plugin_license.py b/src/licensedcode/plugin_license.py index d7837f4e0b1..d54cf53d708 100644 --- a/src/licensedcode/plugin_license.py +++ b/src/licensedcode/plugin_license.py @@ -304,6 +304,9 @@ def add_referenced_filenames_license_matches_for_detections(resource, codebase): path=referenced_resource.path ) + if not referenced_detections: + continue + referenced_license_expression = combine_expressions( expressions=[ detection["license_expression"] @@ -314,7 +317,7 @@ def add_referenced_filenames_license_matches_for_detections(resource, codebase): referenced_license_expression=referenced_license_expression, license_detection=license_detection, ): - if TRACE_REFERENCE: + if TRACE_REFERENCE and referenced_resource: logger_debug( f'use_referenced_license_expression: False for ' f'resource: {referenced_resource.path} and ' @@ -322,7 +325,7 @@ def add_referenced_filenames_license_matches_for_detections(resource, codebase): ) continue - if TRACE_REFERENCE: + if TRACE_REFERENCE and referenced_resource: logger_debug( f'use_referenced_license_expression: True for ' f'resource: {referenced_resource.path} and ' diff --git a/src/packagedcode/licensing.py b/src/packagedcode/licensing.py index 70c34722ade..ee7178da282 100644 --- a/src/packagedcode/licensing.py +++ b/src/packagedcode/licensing.py @@ -140,6 +140,9 @@ def add_referenced_license_matches_for_package(resource, codebase): ): continue + if not (referenced_resource and referenced_resource.license_detections): + continue + modified = True detections_added.extend(referenced_resource.license_detections) matches_to_extend = get_matches_from_detection_mappings(