Returning iterables from task

I am trying to do this:

from prefect import flow, task

@task
def get_xy():
    return 1, 2

@task
def add_xy(x, y):
    return x + y

@flow
def a_flow():
    x, y = get_xy()
    return add_xy(x, y)

a_flow()

But I get result=TypeError('cannot unpack non-iterable PrefectFuture object'),

2 Likes

To fix, I needed to call .result() after calling the task returning an iterable

from prefect import flow, task

@task
def get_xy():
    return 1, 2

@task
def add_xy(x, y):
    return x + y

@flow
def a_flow():
    x, y = get_xy().result()
    return add_xy(x, y)

a_flow()
3 Likes