I am getting `'FunctionTask' object is not iterabl...
# ask-community
a
I am getting
'FunctionTask' object is not iterable
error. Can anyone point me out, what it is?
j
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
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
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
ahhh, will try that thanks
j
@Marvin archive “Error unpacking task: `'FunctionTask' object is not iterable`”
@Chris White some help 😉
a
@Jeremiah thanks, that helps! Then I have to make sure what get passed around between
task
.
c
@Marvin archive “Error unpacking task: `'FunctionTask' object is not iterable`”