Skip to content

Commit 379442f

Browse files
deduplication: return modified findings
1 parent d0c1e74 commit 379442f

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

dojo/finding/deduplication.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -700,21 +700,25 @@ def _flush_duplicate_changes(modified_new_findings):
700700
save() call per finding. Uses bulk_update (no signals) which is consistent
701701
with the original code that called super(Finding, ...).save(skip_validation=True),
702702
bypassing Finding.save() in both cases.
703+
704+
Returns the list of modified findings so callers can perform any follow-up
705+
processing (e.g. triggering prioritization) on the affected findings.
703706
"""
704707
if modified_new_findings:
705708
Finding.objects.bulk_update(
706709
modified_new_findings,
707710
["duplicate", "active", "verified", "duplicate_finding"],
708711
)
712+
return modified_new_findings
709713

710714

711715
def _dedupe_batch_hash_code(findings):
712716
if not findings:
713-
return
717+
return []
714718
test = findings[0].test
715719
candidates_by_hash = find_candidates_for_deduplication_hash(test, findings)
716720
if not candidates_by_hash:
717-
return
721+
return []
718722
modified_new_findings = []
719723
for new_finding in findings:
720724
deduplicationLogger.debug(f"deduplication start for finding {new_finding.id} with DEDUPE_ALGO_HASH_CODE")
@@ -724,16 +728,16 @@ def _dedupe_batch_hash_code(findings):
724728
break
725729
except Exception as e:
726730
deduplicationLogger.debug(str(e))
727-
_flush_duplicate_changes(modified_new_findings)
731+
return _flush_duplicate_changes(modified_new_findings)
728732

729733

730734
def _dedupe_batch_unique_id(findings):
731735
if not findings:
732-
return
736+
return []
733737
test = findings[0].test
734738
candidates_by_uid = find_candidates_for_deduplication_unique_id(test, findings)
735739
if not candidates_by_uid:
736-
return
740+
return []
737741
modified_new_findings = []
738742
for new_finding in findings:
739743
deduplicationLogger.debug(f"deduplication start for finding {new_finding.id} with DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL")
@@ -745,17 +749,17 @@ def _dedupe_batch_unique_id(findings):
745749
break
746750
except Exception as e:
747751
deduplicationLogger.debug(f"Exception when deduplicating finding {new_finding.id} against candidate {match.id}: {e!s}")
748-
_flush_duplicate_changes(modified_new_findings)
752+
return _flush_duplicate_changes(modified_new_findings)
749753

750754

751755
def _dedupe_batch_uid_or_hash(findings):
752756
if not findings:
753-
return
757+
return []
754758

755759
test = findings[0].test
756760
candidates_by_uid, existing_by_hash = find_candidates_for_deduplication_uid_or_hash(test, findings)
757761
if not (candidates_by_uid or existing_by_hash):
758-
return
762+
return []
759763
modified_new_findings = []
760764
for new_finding in findings:
761765
deduplicationLogger.debug(f"deduplication start for finding {new_finding.id} with DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL_OR_HASH_CODE")
@@ -768,16 +772,16 @@ def _dedupe_batch_uid_or_hash(findings):
768772
break
769773
except Exception as e:
770774
deduplicationLogger.debug(str(e))
771-
_flush_duplicate_changes(modified_new_findings)
775+
return _flush_duplicate_changes(modified_new_findings)
772776

773777

774778
def _dedupe_batch_legacy(findings):
775779
if not findings:
776-
return
780+
return []
777781
test = findings[0].test
778782
candidates_by_title, candidates_by_cwe = find_candidates_for_deduplication_legacy(test, findings)
779783
if not (candidates_by_title or candidates_by_cwe):
780-
return
784+
return []
781785
modified_new_findings = []
782786
for new_finding in findings:
783787
deduplicationLogger.debug(f"deduplication start for finding {new_finding.id} with DEDUPE_ALGO_LEGACY")
@@ -787,7 +791,7 @@ def _dedupe_batch_legacy(findings):
787791
break
788792
except Exception as e:
789793
deduplicationLogger.debug(str(e))
790-
_flush_duplicate_changes(modified_new_findings)
794+
return _flush_duplicate_changes(modified_new_findings)
791795

792796

793797
def dedupe_batch_of_findings(findings, *args, **kwargs):
@@ -800,7 +804,7 @@ def dedupe_batch_of_findings(findings, *args, **kwargs):
800804

801805
if not findings:
802806
logger.debug("dedupe_batch_of_findings called with no findings")
803-
return None
807+
return []
804808

805809
enabled = System_Settings.objects.get().enable_deduplication
806810

@@ -813,19 +817,19 @@ def dedupe_batch_of_findings(findings, *args, **kwargs):
813817

814818
if dedup_alg == settings.DEDUPE_ALGO_HASH_CODE:
815819
logger.debug(f"deduplicating finding batch with DEDUPE_ALGO_HASH_CODE - {len(findings)} findings")
816-
_dedupe_batch_hash_code(findings)
820+
return _dedupe_batch_hash_code(findings)
817821
elif dedup_alg == settings.DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL:
818822
logger.debug(f"deduplicating finding batch with DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL - {len(findings)} findings")
819-
_dedupe_batch_unique_id(findings)
823+
return _dedupe_batch_unique_id(findings)
820824
elif dedup_alg == settings.DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL_OR_HASH_CODE:
821825
logger.debug(f"deduplicating finding batch with DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL_OR_HASH_CODE - {len(findings)} findings")
822-
_dedupe_batch_uid_or_hash(findings)
826+
return _dedupe_batch_uid_or_hash(findings)
823827
else:
824828
logger.debug(f"deduplicating finding batch with LEGACY - {len(findings)} findings")
825-
_dedupe_batch_legacy(findings)
829+
return _dedupe_batch_legacy(findings)
826830
else:
827831
deduplicationLogger.debug("dedupe: skipping dedupe because it's disabled in system settings get()")
828-
return None
832+
return []
829833

830834

831835
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)