From 264ccadda08bf9fc68cad3a7af1e91e2716b7de7 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Tue, 8 Sep 2026 16:19:53 +0800 Subject: [PATCH 1/2] Ensure the status was not updated after scanned #2228 Signed-off-by: Chin Yeung Li --- scanpipe/pipes/d2d.py | 30 ++++++++++++++++++++++++------ scanpipe/tests/pipes/test_d2d.py | 28 ++++++++++++++++++---------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/scanpipe/pipes/d2d.py b/scanpipe/pipes/d2d.py index eda7703e38..8951143fcc 100644 --- a/scanpipe/pipes/d2d.py +++ b/scanpipe/pipes/d2d.py @@ -1556,11 +1556,20 @@ def scan_ignored_to_files(project, logger=None): .to_codebase() .filter(status=flag.IGNORED_FROM_CONFIG) ) + + # Capture the specific files id + scan_file_ids = list(scan_files.values_list("id", flat=True)) + + if not scan_file_ids: + return + scancode.scan_for_files(project, scan_files, progress_logger=logger) - project.codebaseresources.files().to_codebase().filter(status=flag.SCANNED).update( - status=flag.IGNORED_FROM_CONFIG - ) + # Revert to the original status value + project.codebaseresources.filter( + id__in=scan_file_ids, + status=flag.SCANNED + ).update(status=flag.IGNORED_FROM_CONFIG) def scan_unmapped_to_files(project, logger=None): @@ -1573,11 +1582,20 @@ def scan_unmapped_to_files(project, logger=None): .to_codebase() .filter(status=flag.REQUIRES_REVIEW) ) + + # Capture the specific files id + scan_file_ids = list(scan_files.values_list("id", flat=True)) + + if not scan_file_ids: + return + scancode.scan_for_files(project, scan_files, progress_logger=logger) - project.codebaseresources.files().to_codebase().filter(status=flag.SCANNED).update( - status=flag.REQUIRES_REVIEW - ) + # Revert to the original status value + project.codebaseresources.filter( + id__in=scan_file_ids, + status=flag.SCANNED + ).update(status=flag.REQUIRES_REVIEW) def flag_deployed_from_resources_with_missing_license(project, doc_extensions=None): diff --git a/scanpipe/tests/pipes/test_d2d.py b/scanpipe/tests/pipes/test_d2d.py index 5ef10243a3..18adc22cae 100644 --- a/scanpipe/tests/pipes/test_d2d.py +++ b/scanpipe/tests/pipes/test_d2d.py @@ -1530,14 +1530,18 @@ def test_scanpipe_pipes_d2d_scan_ignored_to_files(self): ) foo_java.update(status=flag.IGNORED_FROM_CONFIG) + # Create another file that is already scanned but should not be + # reverted + other_scanned = make_resource_file( + self.project1, "to/other_scanned.txt", status=flag.SCANNED + ) + d2d.scan_ignored_to_files(self.project1) foo_java.refresh_from_db() + other_scanned.refresh_from_db() - expected = self.project1.codebaseresources.filter( - status=flag.IGNORED_FROM_CONFIG - ).count() - - self.assertEqual(1, expected) + self.assertEqual(flag.IGNORED_FROM_CONFIG, foo_java.status) + self.assertEqual(flag.SCANNED, other_scanned.status) def test_scan_unmapped_to_files(self): to_dir = ( @@ -1558,14 +1562,18 @@ def test_scan_unmapped_to_files(self): ) foo_java.update(status=flag.REQUIRES_REVIEW) + # Create another file that is already scanned but should not be + # reverted + other_scanned = make_resource_file( + self.project1, "to/other_scanned.txt", status=flag.SCANNED + ) + d2d.scan_unmapped_to_files(self.project1) foo_java.refresh_from_db() + other_scanned.refresh_from_db() - expected = self.project1.codebaseresources.filter( - status=flag.REQUIRES_REVIEW - ).count() - - self.assertEqual(1, expected) + self.assertEqual(flag.REQUIRES_REVIEW, foo_java.status) + self.assertEqual(flag.SCANNED, other_scanned.status) def test_flag_deployed_from_resources_with_missing_license(self): from_dir = ( From 5c3afe775de6f8ee558679b5d2a3b79b5fa7cb7d Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Tue, 8 Sep 2026 18:26:33 +0800 Subject: [PATCH 2/2] Code formatting #2228 Signed-off-by: Chin Yeung Li --- scanpipe/pipes/d2d.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/scanpipe/pipes/d2d.py b/scanpipe/pipes/d2d.py index 8951143fcc..a9d7d486b3 100644 --- a/scanpipe/pipes/d2d.py +++ b/scanpipe/pipes/d2d.py @@ -1566,10 +1566,9 @@ def scan_ignored_to_files(project, logger=None): scancode.scan_for_files(project, scan_files, progress_logger=logger) # Revert to the original status value - project.codebaseresources.filter( - id__in=scan_file_ids, - status=flag.SCANNED - ).update(status=flag.IGNORED_FROM_CONFIG) + project.codebaseresources.filter(id__in=scan_file_ids, status=flag.SCANNED).update( + status=flag.IGNORED_FROM_CONFIG + ) def scan_unmapped_to_files(project, logger=None): @@ -1592,10 +1591,9 @@ def scan_unmapped_to_files(project, logger=None): scancode.scan_for_files(project, scan_files, progress_logger=logger) # Revert to the original status value - project.codebaseresources.filter( - id__in=scan_file_ids, - status=flag.SCANNED - ).update(status=flag.REQUIRES_REVIEW) + project.codebaseresources.filter(id__in=scan_file_ids, status=flag.SCANNED).update( + status=flag.REQUIRES_REVIEW + ) def flag_deployed_from_resources_with_missing_license(project, doc_extensions=None):