I’m trying to write a flow that creates a number o...
# prefect-community
m
I’m trying to write a flow that creates a number of sub-flows and running into some issues getting Prefect to register it- would appreciate some guidance (example in thread)
discourse 1
Following https://docs.prefect.io/core/idioms/flow-to-flow.html#running-a-parametrized-flow as a baseline, my flow basically looks like:
Copy code
def 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?
k
So
task_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:
Copy code
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.
m
This worked out perfectly- thanks so much!