Have just come across this error when trying to us...
# ask-community
j
Have just come across this error when trying to use my own custom decorator;
Copy code
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.
Has anyone had any luck using their own? The one I want to use is this;
Copy code
def jitter(func: Callable) -> Callable:
    """
    For use with short running mapped tasks
    to avoid overwhelming the api server

    calls function sleeps for random period
    """

    def wrapped(*args, **kwargs):
        res = func(*args, **kwargs)

        sleep(random.gauss(1.2, 0.2))
        return res

    return wrapped
Basically just waits for a while and does so randomly so lots of short running mapped tasks don't all hit my api server (on k8s) - I much prefer this than having sleeps in my actual task code
But perhaps its just the case that you cant really use a custom decorator with the task one?
j
Try wrapping your
def wrapped
with
functools.wraps
Copy code
import functools

def jitter(func: Callable) -> Callable:
    """
    For use with short running mapped tasks
    to avoid overwhelming the api server
    calls function sleeps for random period
    """
    @functools.wraps(func)
    def wrapped(*args, **kwargs):
        res = func(*args, **kwargs)
        sleep(random.gauss(1.2, 0.2))
        return res
    return wrapped
j
ohhh thats clever I thought it just did cosmetic things!
doc string, name etc
j
It also forwards signature inference, which is the issue you were running into.
j
Yeah I see that now! Thanks very much!