is it possible to access `runtime.deployment` info...
# ask-community
d
is it possible to access
runtime.deployment
information when setting a Flow's run name? here's an example:
Copy code
from prefect import flow, runtime
import datetime

def get_flow_run_name():
    date = datetime.datetime.now().isoformat()
    return f"{runtime.deployment.name}-{date}"

@flow(log_prints=True, flow_run_name=get_flow_run_name)
def hi_named_flow(name: str):
    print(f"Hi {name}")
when I try to deploy this with local Prefect server, agent, and storage, the flow run hangs here:
Copy code
11:32:06.748 | INFO    | Flow run 'warm-numbat' - Downloading flow code from storage at '/<some_path>/flows/test'
but if use
runtime.flow_run.flow_name
instead of
runtime.deployment.name
, it works
j
Hi @Dominick Olivito - thanks for the question! That looks like it should work. I’m on mobile right now but will try replicate when I’m on my laptop.
d
thanks for looking into it. this was on
2.10.12
j
Hey @Dominick Olivito - sorry for the delay. I tried this out and the following works for me:
Copy code
from prefect import flow, runtime
import datetime

def get_flow_run_name():
    date = datetime.datetime.now().isoformat()
    return f"{runtime.deployment.name}-{date}"

@flow(log_prints=True, flow_run_name=get_flow_run_name())
def hi_named_flow(name: str):
    print(f"Hi {name}")
Note that I'm calling the
get_flow_run_name
function.
d
thanks for the reply here. that's interesting - the examples in the Prefect docs that I was looking at pass the function as an object instead of calling it to return the value. specifically:
Copy code
@flow(flow_run_name=get_flow_run_name)

# instead of 

@flow(flow_run_name=get_flow_run_name())
https://docs.prefect.io/2.10.12/concepts/flows/#flow-settings is it true that the former is evaluated at flow run time, while the latter is evaluated at deployment time?
j
It's all at run time. (We don't access your deployed code - it's all done by your worker). Good points on the docs example. I'll open an issue as I can reproduce your hanging run and wouldn't expect that either way.
👍 1