https://prefect.io logo
Title
a

Abhinav Chordia

05/08/2023, 8:31 PM
Has anyone tried extending the flow and task decorators to add some common functionality across flows?
d

Deceivious

05/08/2023, 8:39 PM
Hi Can you be more specific ?
a

Abhinav Chordia

05/08/2023, 8:49 PM
Things like common logging or task runners, or artifact creation
d

Deceivious

05/08/2023, 8:57 PM
Just new decorator that implements storage and cache parameters based on the environment .
cached_task
and
stored_task
a

Abhinav Chordia

05/08/2023, 9:16 PM
The problem is that flow and task decorators return the Flow and Task objects
d

Deceivious

05/08/2023, 9:37 PM
overwritten with with_options
a

Abhinav Chordia

05/08/2023, 9:50 PM
Not following, I’m relatively new with python. Can you share an example?
d

Deceivious

05/09/2023, 8:12 AM
def stored_task(**k_args):
    """Decorator for standardized storage enabled tasks"""

    def decorator(fn):
        """Passes function"""

        @task
        def _inner(*inner_args, **inner_k_args):
            """Task decoration method"""
            return fn(*inner_args, **inner_k_args)

        return _inner.with_options(**k_args, **get_storage_parameters())

    return decorator
ah if you are new to python, this might confuse you more.
what is your issue?
a

Abhinav Chordia

05/09/2023, 11:17 PM
That implementation returns a function where the @task decorator returns a Task object