Hi folks we came across a bug when chaining more t...
# prefect-community
m
Hi folks we came across a bug when chaining more than one decorator with the prefect task decorator
👍 1
basically the method
_validate_run_signature
tries to unwrap the function provided to get to the underlying function but it does so by accessing
___wrapped___
instead of using something like`inspect.unwrap` that would traverse the
___wrapped___
chain …
so a simple decorator like this:
Copy code
def simple_dec(func):
    @functools.wraps(func)
    def wrapped(*args, **kwargs):
        return func(*args, **kwargs)
    return wrapped
would work fine when chained with a task decorator - i.e.
Copy code
@task
@simple_dec
def test(a: int, b:int) -> int:
    return a + b
but chaining the simple decorator more than once would fail -i.e.
Copy code
@task
@simple_dec
@simple_dec
def test(a: int, b:int) -> int:
    return a + b
with the following error
Copy code
Traceback (most recent call last):
  File "./_tmp/r.py", line 16, in <module>
    def test(a: int, b: int) -> int:
  File "/Users/marwansarieddine/.pyenv/versions/3.8.5/envs/pyinfima/lib/python3.8/site-packages/prefect/utilities/tasks.py", line 408, in task
    return prefect.tasks.core.function.FunctionTask(fn=fn, **task_init_kwargs)
  File "/Users/marwansarieddine/.pyenv/versions/3.8.5/envs/pyinfima/lib/python3.8/site-packages/prefect/core/task.py", line 158, in init
    old_init(self, *args, **kwargs)
  File "/Users/marwansarieddine/.pyenv/versions/3.8.5/envs/pyinfima/lib/python3.8/site-packages/prefect/tasks/core/function.py", line 60, in __init__
    prefect.core.task._validate_run_signature(fn)  # type: ignore
  File "/Users/marwansarieddine/.pyenv/versions/3.8.5/envs/pyinfima/lib/python3.8/site-packages/prefect/core/task.py", line 66, in _validate_run_signature
    raise ValueError(
ValueError: Tasks with variable positional arguments (*args) are not supported, because all Prefect arguments are stored as keywords. As a workaround, consider modifying the run() method to accept **kwargs and feeding the values to *args.
Please see this PR that should solve this issue https://github.com/PrefectHQ/prefect/pull/4053
note this issue also presents itself when using a complex decorator (i.e a decorator that calls another decorator inside of it) in tandem with the task decorator …
c
Thanks for the PR!
👍 1