1515 Test_Import ,
1616)
1717from dojo .notifications .helper import create_notification
18+ from dojo .decorators import we_want_async
1819from dojo .validators import clean_tags
1920
2021logger = logging .getLogger (__name__ )
@@ -159,7 +160,7 @@ def process_findings(
159160 from dojo .finding import helper as finding_helper
160161 from dojo .models import Dojo_User
161162 from dojo .utils import calculate_grade , calculate_grade_signature
162- task_signatures = []
163+ post_processing_task_signatures = []
163164
164165 """
165166 Saves findings in memory that were parsed from the scan report into the database.
@@ -233,29 +234,17 @@ def process_findings(
233234
234235 # Collect finding for parallel processing - we'll process them all at once after the loop
235236 push_to_jira = self .push_to_jira and (not self .findings_groups_enabled or not self .group_by )
236- # Process finding - either sync or async based on block_execution
237- if Dojo_User .wants_block_execution (self .user ):
238- # This will run synchronously, but we still call the dojo_async decorated function to count the task
239- finding_helper .post_process_finding_save (
237+ # Always create signatures - we'll execute them sync or async later
238+ post_processing_task_signatures .append (
239+ finding_helper .post_process_finding_save_signature (
240240 finding ,
241241 dedupe_option = True ,
242242 rules_option = True ,
243243 product_grading_option = False ,
244244 issue_updater_option = True ,
245245 push_to_jira = push_to_jira ,
246- )
247- else :
248- # Add to task signatures for async execution
249- task_signatures .append (
250- finding_helper .post_process_finding_save_signature (
251- finding ,
252- dedupe_option = True ,
253- rules_option = True ,
254- product_grading_option = False ,
255- issue_updater_option = True ,
256- push_to_jira = push_to_jira ,
257- ),
258- )
246+ ),
247+ )
259248
260249 for (group_name , findings ) in group_names_to_findings_dict .items ():
261250 finding_helper .add_findings_to_auto_group (
@@ -273,19 +262,18 @@ def process_findings(
273262
274263 # Calculate product grade after all findings are processed
275264 product = self .test .engagement .product
276- if task_signatures :
265+ if post_processing_task_signatures :
277266 # If we have async tasks, use chord to wait for them before calculating grade
278- if Dojo_User .wants_block_execution (self .user ):
279- # Run the chord synchronously by passing sync=True to each task
280- for task_sig in task_signatures :
281- task_sig .apply_async (sync = True ).get ()
282- calculate_grade (product , sync = True )
267+ if we_want_async (async_user = self .user ):
268+ # Run the chord asynchronously and after completing post processing tasks, calculate grade ONCE
269+ chord (post_processing_task_signatures )(calculate_grade_signature (product ))
283270 else :
284- # Run the chord asynchronously
285- chord (task_signatures )(calculate_grade_signature (product ))
286- else :
287- # If everything was sync, calculate grade now as post processing is done
288- calculate_grade (product )
271+ # Execute each task synchronously
272+ for task_sig in post_processing_task_signatures :
273+ task_sig ()
274+
275+ # Calculate grade, which can be prelimary calculated before the async tasks have finished
276+ calculate_grade (product )
289277
290278 sync = kwargs .get ("sync" , True )
291279 if not sync :
0 commit comments