Hi everyone, a question about Prefect 1. I am trying to run a subflow using a task.
My code:
Copy code
@task(log_stdout=True)
def create_subflows(list_of_elements):
list_param= []
for element in list_of_elements:
list_param.append(
{
"pr": element,
}
)
mapped_flows = create_flow_run.map(
flow_name=unmapped("Subflow"),
parameters=list_param,
)
with Flow("Parent Flow") as flow:
list_of_elements = [1,2,3]
create_subflows(list_of_elements)
I am getting this error:
`ValueError: Could not infer an active Flow context while creating edge to <Task: create_flow_run>. This often means you called a task outside a with Flow(...) block. If you're trying to run this task outside of a Flow context, you need to call
@Anna Geller sorry, that was a mistake when I wrote the example. I am already using the @task decorator. I updated my code.
a
Anna Geller
07/15/2022, 10:01 AM
Gotcha, still this is not the right syntax to use subflows, both mapping and create_flow_run tasks must to be called within a Flow construct, check out those examples: https://discourse.prefect.io/tag/flow-of-flows
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.