09/16/2020, 12:40 PM
Hi folks. I have another short question. Is it possible to get more than one return value from a task inside a flow context e.g.:
Copy code
with Flow("Flow1") as flow:
    config = get_config('local')
    value1, value2 = task1()
If i try this i get : TypeError: 'FunctionTask' object is not iterable

Mark Koob

09/16/2020, 12:57 PM
Hey Sebastian - I've gotten around this by having the task return an iterable and then explicitly unpacking the values in the flow.
Copy code
iterable = task1()
value1 = iterable[1] # or maybe it has to be FunctionTask(lambda x: x[1])?


09/16/2020, 1:06 PM
I am also thinking about using a dict with the packed values or something like that, but i am not quite satisfied with that solution


09/16/2020, 1:13 PM
Hey @sebastian.clanzett the reason why it is unable to unpack the two values from your
is due to the fact that prefect doesn’t know the result of that task until runtime so Python can’t do the unpacking. (prefect uses a deferred computation model for flow building) Python will let you index the result from that task if that suites your needs:
Copy code
def a():
    return 1, 2

def b(x, y):
    print(x + y)

with Flow('unpack') as flow:
    res = a()
    b(res[0], res[1])


09/16/2020, 1:15 PM
ah ok. this is how it works. thx alot