https://prefect.io logo
#prefect-community
Title
# prefect-community
a

Akshay Verma

08/19/2019, 1:04 PM
I am getting
'FunctionTask' object is not iterable
error. Can anyone point me out, what it is?
j

Jeremiah

08/19/2019, 1:05 PM
Hi @Akshay Verma, it sounds like you are trying to iterate over a task (or possibly the result of calling a task, which is also a task). Hard to say without more code - can you provide an example?
a

Akshay Verma

08/19/2019, 1:11 PM
i am doing the following:
Copy code
@task
def generate_context_level_data(mlsi, lvnr, tol):
    ml, ci = td_split_clv(mlsi, lvnr, tol)
    return ml, ci

td_input = {'a': 1, 'b': 2, 'c': 3}
with Flow('TD') as flow:
    td_input = Parameter("td_input")
    context_level_ml, context_level_ci = generate_context_level_data(td_input['a'],
                                                 td_input['b'],
                                                 td_input['c'])
j

Jeremiah

08/19/2019, 1:12 PM
Ah ok, it’s because you are assigning the result of
generate_context_level_data
to two variables (
context_level_ml
and
context_level_ci
), but Prefect doesn’t know what the result of
generate_context_level_data
is, so Python can’t do that unpacking.
Try this instead:
Copy code
context_result = generate_context_level_data(...)
context_level_ml = context_result[0]
context_level_ci = context_result[1]
Python will let us index an unknown object like
context_result
, but not unpack it.
(Note, I can’t promise this will work exactly as written because it depends on what is actually coming out of
generate_context_level_data
but this pattern should work — return a single object from your task, then index it appropriately)
a

Akshay Verma

08/19/2019, 1:22 PM
ahhh, will try that thanks
j

Jeremiah

08/19/2019, 1:23 PM
@Marvin archive “Error unpacking task: `'FunctionTask' object is not iterable`”
@Chris White some help 😉
a

Akshay Verma

08/19/2019, 1:47 PM
@Jeremiah thanks, that helps! Then I have to make sure what get passed around between
task
.
c

Chris White

08/19/2019, 6:13 PM
@Marvin archive “Error unpacking task: `'FunctionTask' object is not iterable`”