Hey prefect team! I'm trying to register multiple ...
# ask-community
c
Hey prefect team! I'm trying to register multiple flows generated in a loop in my file. However, it seems to only register the latest flow in the loop. Whats the right way to do this?
k
Hey @Charles Leung, are you using
flow.register()
or the Prefect CLI?
c
the prefect CLI
i have a factory function that reads in a list, and then iterate over each item and generate a flow using this factory function.
k
Do you store the flows in a list? or is it always overwriting the latest flow?
Ok I just tried that won’t work. Let me test a bit
You need to do something like this. You need to unpack it somehow in the end because register will look for
flow
objects
Copy code
from prefect import Flow, task

with Flow("a") as flow:
    task(lambda x: x+ 1)(1)

flows = []
for i in list(range(3)):
    with Flow("a"+str(i)) as flow:
        task(lambda x: x+ 1)(i)
    flows.append(flow.copy())

x, y, z = flows
But this will repeat the registration of the last flow twice (because it exists in
flow
and in
z
) so you need to
del flow
c
ah, so the way registration works is by looking through globals?
k
Let me look for the specific code
Specifically this line
c
great 🙂 thanks kevin!
👍 1
globals().update(flows), where flows is a dictioanry works
k
That’s nice!