https://prefect.io logo
Title
m

Mohamed Hatem Diabi

07/15/2022, 12:13 AM
Hi everyone, a question about Prefect 1. I am trying to run a subflow using a task. My 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
create_flow_run.run(...)
1
a

Anna Geller

07/15/2022, 1:27 AM
instead of
@Task
you would need a decorator
@task
and for subflows in 1.0, check out those examples: https://discourse.prefect.io/tag/flow-of-flows
m

Mohamed Hatem Diabi

07/15/2022, 3:45 AM
@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