@@ -126,11 +126,14 @@ def _update_status(tb_id, status, exception=None):
126126 base = dict (current .data ) if current .data else None
127127 data = DefaultMergeStrategy ().merge (base , {"exception" : str (exception )})
128128 if data is not None :
129- update_task_safe (tb_id , status = status , data = data )
129+ updated = update_task_safe (tb_id , status = status , data = data )
130130 else :
131- update_task_safe (tb_id , status = status )
131+ updated = update_task_safe (tb_id , status = status )
132132 else :
133- update_task_safe (tb_id , status = status )
133+ updated = update_task_safe (tb_id , status = status )
134+
135+ if updated is not None :
136+ _task_cache .set (tb_id , updated )
134137
135138
136139class _Cache :
@@ -170,8 +173,9 @@ def _wrap_defer(task):
170173 """Wrap ``task.defer`` and ``task.defer_async`` so they create a TaskBadger
171174 task in PENDING state and inject its id into the job's task_kwargs.
172175
173- The original defer methods are stashed on the task to keep the wrap
174- idempotent (a second call replaces nothing because the marker is set)."""
176+ Not idempotent on its own — the caller (``_instrument_task``) gates this
177+ via ``_INSTRUMENTED_ATTR`` so each task is wrapped at most once.
178+ """
175179 original_defer = task .defer
176180 original_defer_async = task .defer_async
177181
0 commit comments