Max Kolasinski
03/08/2022, 3:49 PMdef get_tasks():
return ["task1", "task2"]
with Flow('my_flow') as flow:
task_list = get_tasks()
for task in task_list:
flow_run = create_flow_run(flow_name="task",
project_name="task",
parameters=task)
On first attempt the Prefect registrar told me that Tasks are not iterable- fair enough- so I instead tried to iterate on task_list.result
and I’m being told that NoneType isn’t iterable either. Is there a way to inform the registrar of the type that I’m expecting to get returned or otherwise some way of tricking the process into accepting the flow? Or am I trying to do something that shouldn’t be done?Kevin Kho
03/08/2022, 3:52 PMtask_list
is not an iterable when the Flow is being built. It is of type Task so you can’t iterate over it. The value into becomes an iterable during runtime. So the paradigm here would be to use mapping:
with Flow('my_flow') as flow:
task_list = get_tasks()
create_flow_run.map(flow_name="task",
project_name="task",
parameters=task)
and that it like a for-loop. In general, you can’t use non-task native Python in the Flow like if
, while
, etc.Max Kolasinski
03/08/2022, 11:38 PM