hey all, is there a way to dynamically name flows ...
# prefect-community
j
hey all, is there a way to dynamically name flows in v1?
Copy code
with prefect.Flow(
    name="SOME_DYNAMIC_NAME" # instead of hardcoding this, i want to pass a value when registering / calling it
šŸ‘€ 1
āœ… 1
we are using flows as templates and passing around a config parameter. one approach is to use static names for flows, and observe each run by clicking in and looking at the config parameter. but we like to observability that named flows provides
b
Hello Jon, to my understanding you want to dynamically generate a name for the flow runs, is that correct? If so, this article has an example which could help with that. You can create a task that creates a
run_name
which is applied when the run is executed.
j
not quite. not the flow run but the flow itself
n
Hi @Jon I don't believe there's a well supported way to do this - what are you trying to accomplish by dynamically naming flows?
j
i think i can solve my issue with dynamically setting labels
šŸ‘ 3
mostly just wanted an easy way to filter flows in the UI
i
Hello @Nate, I need to change the flow name, too. As far as I understand, there is no way to change it, right? I applied the following solution, but it did not work https://discourse.prefect.io/t/set-name-for-flow-run-and-mapped-task-runs/1866/6
n
Hi @Ismail Cenik - the solution you linked above is for Prefect 2, is that what you're using? The original poster in this thread was asking about prefect v1
i
Hello, Mine is Prefect 2 as well. So what can we do?
n
there are multiple ways you can set the flow name, I'm not sure that this is what you're looking for, but I'll show a couple examples in case that's helpful: ā€¢ simplest way to name a flow
Copy code
@flow(name="My Flow")
def my_flow():
   pass
ā€¢ name a flow that is already defined
Copy code
# using above example
my_new_named_flow = my_flow.with_options(name="My New Named Flow")
# `my_new_named_flow` can now be called just like any other flow
is there a different way in which you're trying to name a flow?
āœ… 1
i
That works for me. Thank you.
One more question, in prefect v1, I set the result into s3 like that
Copy code
with Flow(flow_name, storage=storageObj, result=s3_backup,
          run_config=KubernetesRun(job_template_path=JOB_TEMPLATE_FILE),
          executor=LocalDaskExecutor(scheduler="threads", num_workers=1)) as flow:
in prefect v2, how can I set it before running the flow? This is a parametric info for us and changing env (DEV, QA, CM, PROD), so how can I set it?
I think, "with_options" might work here as well, let me try it
šŸ‘ 1