Skip to content

Commit 715d4e1

Browse files
refactor: rename dispatch kwarg sync= to force_sync= (#14882)
The `sync=True` kwarg on dojo_dispatch_task / dojo_async_task forces the target task to run in the foreground. The bare name `sync` collides with unrelated `sync` parameters elsewhere in the codebase (e.g. JIRA Instance's `finding_jira_sync`, `is_keep_in_sync`) and is asymmetric with the recently-introduced `force_async=True` knob. Rename to `force_sync=` for clarity and symmetry. Hard rename — no alias. Callers updated: - dojo/decorators.py — we_want_async reads `force_sync` instead of `sync`. - dojo/celery_dispatch.py — docstring. - dojo/celery.py — DojoAsyncTask.apply_async pops `force_sync` from kwargs. - dojo/importers/default_importer.py, default_reimporter.py — propagate `force_sync` from importer kwargs to post_process_findings_batch. - dojo/finding/helper.py — post_process_findings_batch signature + nested dojo_dispatch_task(calculate_grade, ..., force_sync=force_sync). - dojo/api_v2/serializers.py, dojo/finding_group/views.py — JIRA push call sites that want foreground execution. - unittests/test_async_delete.py, test_reimport_prefetch.py, test_update_import_history.py — updated kwargs + docstrings.
1 parent e1f2163 commit 715d4e1

11 files changed

Lines changed: 20 additions & 20 deletions

File tree

dojo/api_v2/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ def update(self, instance, validated_data):
14741474

14751475
if push_to_jira or jira_services.is_keep_in_sync(instance):
14761476
# Push synchronously so that we can see jira errors in real time
1477-
success, message = jira_services.push(instance, sync=True)
1477+
success, message = jira_services.push(instance, force_sync=True)
14781478
if not success:
14791479
raise serializers.ValidationError(message)
14801480

dojo/celery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def apply_async(self, args=None, kwargs=None, **options):
6767
kwargs["async_user_id"] = user.id if user else None
6868

6969
# Control flag used for sync/async decision; never pass into the task itself
70-
kwargs.pop("sync", None)
70+
kwargs.pop("force_sync", None)
7171

7272
# Track dispatch
7373
dojo_async_task_counter.incr(

dojo/celery_dispatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def dojo_dispatch_task(task_or_sig: _SupportsSi | _SupportsApplyAsync | Signatur
6161
6262
- Inject `async_user_id` if missing.
6363
- Capture and inject pghistory context if available.
64-
- Respect `sync=True` (foreground execution) and user `block_execution`.
64+
- Respect `force_sync=True` (foreground execution) and user `block_execution`.
6565
- Support `countdown=<seconds>` for async dispatch.
6666
6767
Returns:

dojo/decorators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def get_tasks(self):
5858
def we_want_async(*args, func=None, **kwargs):
5959
from dojo.utils import get_current_user # noqa: PLC0415 circular import
6060

61-
sync = kwargs.get("sync", False)
62-
if sync:
63-
logger.debug("dojo_async_task %s: running task in the foreground as sync=True has been found as kwarg", func)
61+
force_sync = kwargs.get("force_sync", False)
62+
if force_sync:
63+
logger.debug("dojo_async_task %s: running task in the foreground as force_sync=True has been found as kwarg", func)
6464
return False
6565

6666
user = get_current_user()

dojo/finding/helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def post_process_findings_batch(
467467
push_to_jira=False,
468468
jira_instance_id=None,
469469
user=None,
470-
sync=False,
470+
force_sync=False,
471471
**kwargs,
472472
):
473473

@@ -510,7 +510,7 @@ def post_process_findings_batch(
510510
if product_grading_option and system_settings.enable_product_grade:
511511
from dojo.celery_dispatch import dojo_dispatch_task # noqa: PLC0415 circular import
512512

513-
dojo_dispatch_task(calculate_grade, findings[0].test.engagement.product.id, sync=sync)
513+
dojo_dispatch_task(calculate_grade, findings[0].test.engagement.product.id, force_sync=force_sync)
514514

515515
# If we received the ID of a jira instance, then we need to determine the keep in sync behavior
516516
jira_instance = None

dojo/finding_group/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def view_finding_group(request, fgid):
9797
elif not finding_group.has_jira_issue:
9898
jira_services.link_finding_group(request, finding_group, jira_issue)
9999
elif push_to_jira:
100-
jira_services.push(finding_group, sync=True)
100+
jira_services.push(finding_group, force_sync=True)
101101

102102
finding_group.save()
103103
return HttpResponseRedirect(reverse("view_test", args=(finding_group.test.id,)))
@@ -194,7 +194,7 @@ def push_to_jira(request, fgid):
194194

195195
# it may look like success here, but the push_to_jira are swallowing exceptions
196196
# but cant't change too much now without having a test suite, so leave as is for now with the addition warning message to check alerts for background errors.
197-
if jira_services.push(group, sync=True):
197+
if jira_services.push(group, force_sync=True):
198198
messages.add_message(
199199
request,
200200
messages.SUCCESS,

dojo/importers/default_importer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def process_findings(
279279
product_grading_option=True,
280280
issue_updater_option=True,
281281
push_to_jira=push_to_jira,
282-
sync=kwargs.get("sync", False),
282+
force_sync=kwargs.get("force_sync", False),
283283
)
284284

285285
# No chord: tasks are dispatched immediately above per batch

dojo/importers/default_reimporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def process_findings(
434434
issue_updater_option=True,
435435
push_to_jira=push_to_jira,
436436
jira_instance_id=getattr(self.jira_instance, "id", None),
437-
sync=kwargs.get("sync", False),
437+
force_sync=kwargs.get("force_sync", False),
438438
)
439439

440440
# No chord: tasks are dispatched immediately above per batch

unittests/test_async_delete.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@ def test_async_delete_product_with_hierarchy(self):
252252
)
253253

254254
@override_settings(ASYNC_OBJECT_DELETE=True)
255-
def test_async_delete_accepts_sync_kwarg(self):
255+
def test_async_delete_accepts_force_sync_kwarg(self):
256256
"""
257-
Test that async_delete passes through the sync kwarg properly.
257+
Test that async_delete passes through the force_sync kwarg properly.
258258
259-
The sync=True kwarg forces synchronous execution for the top-level task.
259+
The force_sync=True kwarg forces synchronous execution for the top-level task.
260260
However, nested task dispatches still need user context to run synchronously,
261261
so we use impersonate here as well.
262262
"""
@@ -265,14 +265,14 @@ def test_async_delete_accepts_sync_kwarg(self):
265265

266266
# Use impersonate to ensure nested tasks also run synchronously
267267
with impersonate(self.testuser):
268-
# Explicitly pass sync=True
268+
# Explicitly pass force_sync=True
269269
async_del = async_delete()
270-
async_del.delete(product, sync=True)
270+
async_del.delete(product, force_sync=True)
271271

272272
# Verify the product was deleted
273273
self.assertFalse(
274274
Product.objects.filter(pk=product_pk).exists(),
275-
"Product should be deleted with sync=True",
275+
"Product should be deleted with force_sync=True",
276276
)
277277

278278
def test_async_delete_helper_methods(self):

unittests/test_reimport_prefetch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def _reimport_with_overridden_hashcode(self):
118118
minimum_severity="Info",
119119
active=True,
120120
verified=True,
121-
sync=True,
121+
force_sync=True,
122122
scan_type=SCAN_TYPE,
123123
)
124124
return reimporter.process_scan(scan)

0 commit comments

Comments
 (0)