Skip to content

Commit c0c9f1a

Browse files
committed
feat(procrastinate): verify pass_context=True works with task wrapper
1 parent c85f9aa commit c0c9f1a

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

taskbadger/procrastinate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def _instrument_task(task, system=None, manual=False, opts=None):
6868
original_func = task.func
6969
is_async = inspect.iscoroutinefunction(original_func)
7070

71+
# pass_context=True works transparently: Procrastinate passes the context
72+
# object as the first positional arg; our *args/**kwargs wrapper forwards it.
7173
if is_async:
7274

7375
@functools.wraps(original_func)

tests/test_procrastinate.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,28 @@ def recorder(a, b):
324324
"existing": 1,
325325
"procrastinate_task_kwargs": {"a": 5, "b": 6},
326326
}
327+
328+
329+
@pytest.mark.usefixtures("_bind_settings")
330+
def test_pass_context_forwards_context(app):
331+
seen = {}
332+
333+
@track
334+
@app.task(name="ctx_task", pass_context=True)
335+
def ctx_task(context, a):
336+
seen["context"] = context
337+
seen["a"] = a
338+
339+
tb = task_for_test()
340+
with (
341+
mock.patch("taskbadger.procrastinate.create_task_safe", return_value=tb),
342+
mock.patch("taskbadger.procrastinate.update_task_safe"),
343+
mock.patch("taskbadger.procrastinate.get_task", return_value=tb),
344+
):
345+
ctx_task.defer(a=42)
346+
app.run_worker(wait=False, install_signal_handlers=False, listen_notify=False)
347+
348+
assert seen["a"] == 42
349+
# Context object should be passed through unchanged
350+
assert seen["context"] is not None
351+
assert seen["context"].task is ctx_task

0 commit comments

Comments
 (0)