Skip to content

Commit

Permalink
Merge pull request #399 from peopledoc/task-attributes-394
Browse files Browse the repository at this point in the history
Attributes on the decorated task function shouldn't leak on the task
  • Loading branch information
Joachim Jablon authored May 21, 2021
2 parents 58185b8 + ecdb0b3 commit e9fc5e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion procrastinate/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _wrap(func: Callable[..., "tasks.Task"]):
)
self._register(task)

return functools.update_wrapper(task, func)
return functools.update_wrapper(task, func, updated=())

if _func is None: # Called as @app.task(...)
return _wrap
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def wrapped():
assert app.tasks["d"] is wrapped


def test_app_task_implicit(app, mocker):
def test_app_task_implicit(app):
@app.task
def wrapped():
return "foo"
Expand All @@ -67,6 +67,19 @@ def wrapped():
assert registered_task.func is wrapped.__wrapped__


def test_app_task_dont_read_function_attributes(app):
# This is a weird one. It's a regression test. At some point, we noted that,
# due to the slightly wrong usage of update_wrapper, the attributes on the
# decorated function were copied on the task. This led to surprising
# behaviour. This test is just here to make sure it doesn't happen again.
def wrapped():
return "foo"

wrapped.pass_context = True
task = app.task(wrapped)
assert task.pass_context is False


def test_app_register_builtins(app):
assert app.queues == {"builtin"}
assert "procrastinate.builtin_tasks.remove_old_jobs" in app.tasks
Expand Down

0 comments on commit e9fc5e6

Please sign in to comment.