Skip to content

Commit 06a8176

Browse files
snopokeclaude
andcommitted
fix(procrastinate): invalidate cache after update; clarify defer wrap docs
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ad65f65 commit 06a8176

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

taskbadger/procrastinate.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

136139
class _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

tests/test_procrastinate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def boom():
8181
mock.patch("taskbadger.procrastinate.get_task") as get,
8282
):
8383
get.return_value = task_for_test(status=StatusEnum.PROCESSING, data={"x": 1})
84+
update.return_value = task_for_test(status=StatusEnum.PROCESSING, data={"x": 1})
8485
with pytest.raises(ValueError, match="nope"):
8586
boom.func(**{TB_TASK_ID_KWARG: "tb-789"})
8687

0 commit comments

Comments
 (0)