class ReturnObject:
def__init__(self, value: str = "hello", list: List = ["world"]):
self.value = value
self.list = list
class MyTask(Task):
def run(self) -> ReturnObject:
return ReturnObject("some value", ["a", "b", "c"])
task = MyTask()
with Flow() as flow:
result = task()
some_other_task(param1=result.value, param2=result.list)
If I try to run this code, I’ll get an error like
Copy code
AttributeError: 'MyTask' object has no attribute 'value'
Josh
02/09/2021, 4:36 PM
If I want to return different type objects from a task to be used in subsequent tasks, what is the Prefect way of doing this?
c
Chris White
02/09/2021, 4:37 PM
Hi Josh - you’re conflating runtime with build time; the result of the first task isn’t available until you’ve run the code, the flow context manager is only building the dependency structure.
You can return arbitrary objects from tasks but you cannot access their attributes as you’re doing here — instead you should perform that attribute access within
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.