https://prefect.io logo
#prefect-community
Title
# prefect-community
f

FuETL

05/30/2022, 6:17 PM
Hey guys, what is the best way to copy a flow? Just use .copy() or deepcopy?
k

Kevin Kho

05/30/2022, 6:19 PM
From experience I think copy works already. But I think I don’t have a better answer for now than “try copy and if it doesn’t work, deepcopy” lol.
f

FuETL

05/30/2022, 6:20 PM
I asking because i have 2 flows and in one of them i'm just replacing the name
but now i start getting odd behaviour
ex
if one flow run first the name stick in the next call to
extract_flow_from_file
i get the same object if i extract the flow that i change the name
k

Kevin Kho

05/30/2022, 6:22 PM
Ah then I guess use deepcopy yep
Copy code
from prefect import Flow, task
from copy import copy

@task
def abc():
    return 1

with Flow("test") as flow:
    abc()

flow2 = copy(flow)
flow2.name = "test2"
print(flow.name)
f

FuETL

05/30/2022, 6:33 PM
great! thanks.
3 Views