Question for the prefect experts. Lets say I have ...
# ask-community
t
Question for the prefect experts. Lets say I have a decorator function>
Copy code
def wrapper(fn):
    def _wrapper():
        return fn
    return _wrapper
In my case I am using the wrapper to provide operations to interact witha. config file that I want to attach to functions that become `task`ifed.
Copy code
@task
@wrapper
def my_task():
   ...
This works perfectly fine functionally. But in the prefect UI I have all my tasks that use this
wrapper
decorator appears as
wrapped-N
, where
N
is the auto-incrementing ID. OK. I expand the decorator to be
Copy code
ef wrapper(fn):
    def _wrapper():
        return fn
     _wrapper.__name__ = fn.__name__
    return _wrapper
Now my tasks appear correctly named in the prefect UI as
my_task-N
. However, if I do:
Copy code
@task
@wrapper
def batman():
    ...

@task
@wrapper
def robin():
    ....
I get the correct tasks
batman-N
and
robin-N
, but the auto-incrementing count
N
is common between them. That is to say, that if I call batman twice and robin twice I have the following tasks in the prefect U:
Copy code
batman-1
batman-2
robin-3
robin-4
Not a deal breaker, but I am curious to know how I should be doing this. I do know of the
functools.wraps
function, but I found that when i used that prefect (or some other internals) were unaware of the extra keyword parameters that were introduced to my decorated function:
Copy code
prefect.exceptions.ParameterBindError: Error binding parameters for function 'task_wsclean_imager': got an unexpected keyword argument 'strategy'.
Function 'task_wsclean_imager' has signature 'in_ms: Union[flint.calibrate.aocalibrate.ApplySolutions, <http://flint.options.MS|flint.options.MS>], wsclean_container: pathlib.Path, update_wsclean_options: Optional[Dict[str, Any]] = None, fits_mask: Optional[flint.naming.FITSMaskNames] = None) -> flint.imager.wsclean.WSCleanCommand' but received args: () and kwargs: ['in_ms', 'wsclean_container', 'strategy', 'mode', 'round'].