1616import dojo .jira_link .helper as jira_helper
1717import dojo .risk_acceptance .helper as ra_helper
1818from dojo .celery import app
19- from dojo .decorators import dojo_async_task , dojo_model_from_id , dojo_model_to_id
19+ from dojo .decorators import dojo_async_task
2020from dojo .endpoint .utils import endpoint_get_or_create , save_endpoints_to_add
2121from dojo .file_uploads .helper import delete_related_files
2222from dojo .finding .deduplication import (
2323 dedupe_batch_of_findings ,
24- do_dedupe_finding ,
24+ do_dedupe_finding_task_internal ,
2525 get_finding_models_for_deduplication ,
2626)
2727from dojo .models import (
4343 close_external_issue ,
4444 do_false_positive_history ,
4545 get_current_user ,
46+ get_object_or_none ,
4647 mass_model_updater ,
4748 to_str_typed ,
4849)
@@ -390,27 +391,14 @@ def add_findings_to_auto_group(name, findings, group_by, *, create_finding_group
390391 finding_group .findings .add (* findings )
391392
392393
393- @dojo_model_to_id
394- @dojo_async_task (signature = True )
395- @app .task
396- @dojo_model_from_id
397- def post_process_finding_save_signature (finding , dedupe_option = True , rules_option = True , product_grading_option = True , # noqa: FBT002
398- issue_updater_option = True , push_to_jira = False , user = None , * args , ** kwargs ): # noqa: FBT002 - this is bit hard to fix nice have this universally fixed
399- """
400- Returns a task signature for post-processing a finding. This is useful for creating task signatures
401- that can be used in chords or groups or to await results. We need this extra method because of our dojo_async decorator.
402- If we use more of these celery features, we should probably move away from that decorator.
403- """
404- return post_process_finding_save_internal (finding , dedupe_option , rules_option , product_grading_option ,
405- issue_updater_option , push_to_jira , user , * args , ** kwargs )
406-
407-
408- @dojo_model_to_id
409394@dojo_async_task
410395@app .task
411- @dojo_model_from_id
412- def post_process_finding_save (finding , dedupe_option = True , rules_option = True , product_grading_option = True , # noqa: FBT002
396+ def post_process_finding_save (finding_id , dedupe_option = True , rules_option = True , product_grading_option = True , # noqa: FBT002
413397 issue_updater_option = True , push_to_jira = False , user = None , * args , ** kwargs ): # noqa: FBT002 - this is bit hard to fix nice have this universally fixed
398+ finding = get_object_or_none (Finding , id = finding_id )
399+ if not finding :
400+ logger .warning ("Finding with id %s does not exist, skipping post_process_finding_save" , finding_id )
401+ return None
414402
415403 return post_process_finding_save_internal (finding , dedupe_option , rules_option , product_grading_option ,
416404 issue_updater_option , push_to_jira , user , * args , ** kwargs )
@@ -429,7 +417,7 @@ def post_process_finding_save_internal(finding, dedupe_option=True, rules_option
429417 if dedupe_option :
430418 if finding .hash_code is not None :
431419 if system_settings .enable_deduplication :
432- do_dedupe_finding (finding , * args , ** kwargs )
420+ do_dedupe_finding_task_internal (finding , * args , ** kwargs )
433421 else :
434422 deduplicationLogger .debug ("skipping dedupe because it's disabled in system settings" )
435423 else :
@@ -448,7 +436,7 @@ def post_process_finding_save_internal(finding, dedupe_option=True, rules_option
448436
449437 if product_grading_option :
450438 if system_settings .enable_product_grade :
451- calculate_grade (finding .test .engagement .product )
439+ calculate_grade (finding .test .engagement .product . id )
452440 else :
453441 deduplicationLogger .debug ("skipping product grading because it's disabled in system settings" )
454442
@@ -465,14 +453,6 @@ def post_process_finding_save_internal(finding, dedupe_option=True, rules_option
465453 jira_helper .push_to_jira (finding .finding_group )
466454
467455
468- @dojo_async_task (signature = True )
469- @app .task
470- def post_process_findings_batch_signature (finding_ids , * args , dedupe_option = True , rules_option = True , product_grading_option = True ,
471- issue_updater_option = True , push_to_jira = False , user = None , ** kwargs ):
472- return post_process_findings_batch (finding_ids , * args , dedupe_option = dedupe_option , rules_option = rules_option , product_grading_option = product_grading_option , issue_updater_option = issue_updater_option , push_to_jira = push_to_jira , user = user , ** kwargs )
473- # Pass arguments as keyword arguments to ensure Celery properly serializes them
474-
475-
476456@dojo_async_task
477457@app .task
478458def post_process_findings_batch (finding_ids , * args , dedupe_option = True , rules_option = True , product_grading_option = True ,
@@ -516,7 +496,7 @@ def post_process_findings_batch(finding_ids, *args, dedupe_option=True, rules_op
516496 tool_issue_updater .async_tool_issue_update (finding )
517497
518498 if product_grading_option and system_settings .enable_product_grade :
519- calculate_grade (findings [0 ].test .engagement .product )
499+ calculate_grade (findings [0 ].test .engagement .product . id )
520500
521501 if push_to_jira :
522502 for finding in findings :
@@ -1038,7 +1018,7 @@ def close_finding(
10381018 ra_helper .risk_unaccept (user , finding , perform_save = False )
10391019
10401020 # External issues (best effort)
1041- close_external_issue (finding , "Closed by defectdojo" , "github" )
1021+ close_external_issue (finding . id , "Closed by defectdojo" , "github" )
10421022
10431023 # JIRA sync
10441024 push_to_jira = False
0 commit comments