Question: is it possible to use the @task decorato...
# ask-community
j
Question: is it possible to use the @task decorator on a class method?
c
I don’t believe so, as Prefect will probably complain that
self
is a missing argument
j
Yep. That is what we are running into
Any ideas for a work around? Besides writing a function that inits the class, runs the function, and returns?
c
I’d recommend subclassing your custom class as a Task:
Copy code
class MyPrefectClass(MyCustomClass, Task):
    ...
    def run(self, *args, **kwags):
        # same logic as the method you wanted to decorate
that way all of your statefulness that you are relying on the class for is tracked on the
Task
object