Hi! I came across <this thread> advising that we u...
# prefect-cloud
c
Hi! I came across this thread advising that we use class methods to execute workflow logic. The test below does support this, but I just wanted to double check that this is still the recommendation (since the thread is sort of old) or if there’s been more functionality added to allow for more flexible use of classes. Thanks for the help! Example in 🧵
This works - the flow is calling a subflow/task with the
return_state
argument to get the flow run id.
Copy code
from prefect import flow, task, Flow
@task
def add_one(val):
    return val + 1

@flow
def print_result():
    result = add_one(1)
    print(result)

@flow
def flow():
    future = print_result(return_state=True)
    return future

state = flow()
print(state.dict()["id"])
However, when i wrap these functions in a class, i get a
prefect.exceptions.ParameterBindError
Copy code
from prefect import flow, task
class MyClass():
    val: int = 1

    @task
    def add_one(self):
        return self.val + 1

    @flow
    def print_result(self):
        result = self.add_one()
        print(result)

@flow
def flow():
    obj:MyClass = MyClass()
    future = obj.print_result(return_state=True)
    return future

state = flow()
Error message:
Copy code
raise ParameterBindError.from_bind_failure(fn, exc, call_args, call_kwargs)
prefect.exceptions.ParameterBindError: Error binding parameters for function 'print_result': missing a required argument: 'self'.
Function 'print_result' has signature 'self' but received args: () and kwargs: {}.
a
I am also getting the same error. Any suggestions on how to navigate this issue?