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.
@@ -240,29 +241,17 @@ def process_findings(
240241
241242 # Collect finding for parallel processing - we'll process them all at once after the loop
242243 push_to_jira = self .push_to_jira and (not self .findings_groups_enabled or not self .group_by )
243- # Process finding - either sync or async based on block_execution
244- if Dojo_User .wants_block_execution (self .user ):
245- # This will run synchronously, but we still call the dojo_async decorated function to count the task
246- finding_helper .post_process_finding_save (
244+ # Always create signatures - we'll execute them sync or async later
245+ post_processing_task_signatures .append (
246+ finding_helper .post_process_finding_save_signature (
247247 finding ,
248248 dedupe_option = True ,
249249 rules_option = True ,
250250 product_grading_option = False ,
251251 issue_updater_option = True ,
252252 push_to_jira = push_to_jira ,
253- )
254- else :
255- # Add to task signatures for async execution
256- task_signatures .append (
257- finding_helper .post_process_finding_save_signature (
258- finding ,
259- dedupe_option = True ,
260- rules_option = True ,
261- product_grading_option = False ,
262- issue_updater_option = True ,
263- push_to_jira = push_to_jira ,
264- ),
265- )
253+ ),
254+ )
266255
267256 for (group_name , findings ) in group_names_to_findings_dict .items ():
268257 finding_helper .add_findings_to_auto_group (
@@ -280,19 +269,18 @@ def process_findings(
280269
281270 # Calculate product grade after all findings are processed
282271 product = self .test .engagement .product
283- if task_signatures :
272+ if post_processing_task_signatures :
284273 # If we have async tasks, use chord to wait for them before calculating grade
285- if Dojo_User .wants_block_execution (self .user ):
286- # Run the chord synchronously by passing sync=True to each task
287- for task_sig in task_signatures :
288- task_sig .apply_async (sync = True ).get ()
289- calculate_grade (product , sync = True )
274+ if we_want_async (async_user = self .user ):
275+ # Run the chord asynchronously and after completing post processing tasks, calculate grade ONCE
276+ chord (post_processing_task_signatures )(calculate_grade_signature (product ))
290277 else :
291- # Run the chord asynchronously
292- chord (task_signatures )(calculate_grade_signature (product ))
293- else :
294- # If everything was sync, calculate grade now as post processing is done
295- calculate_grade (product )
278+ # Execute each task synchronously
279+ for task_sig in post_processing_task_signatures :
280+ task_sig ()
281+
282+ # Calculate grade, which can be prelimary calculated before the async tasks have finished
283+ calculate_grade (product )
296284
297285 sync = kwargs .get ("sync" , True )
298286 if not sync :
0 commit comments