<@ULVA73B9P> how can I access the flow name in the...
# ask-marvin
j
@Marvin how can I access the flow name in the template syntax from the work pool base job template
generateName
value? I want to add a prefix to each value, and then have the prefect flow name follow that. Right now,
generateName: <prefix>-{{ name }}
returns
<prefix>-<number_sequence>
instead of the flow name
m
It seems there isn't a direct way to access the flow name using the
{{ name }}
template syntax in the
generateName
field. The
{{ name }}
placeholder is generating a unique sequence instead of using the flow name. From the documentation, the configuration for work pool jobs uses placeholders defined in the variables section, and unfortunately, it doesn't specifically outline how to access the flow name directly in the
generateName
template. However, if accessing the flow name is critical, you might consider using Prefect's runtime context to set the flow run name dynamically. Here is a workaround to set the flow run name with a prefix dynamically: 1. Configure the Flow: Define your flow and use the flow's runtime to access its name.
Copy code
python
from prefect import flow
from prefect.runtime import flow_run

def generate_flow_name():
    return f"prefix-{flow_run.flow_name}"

@flow(flow_run_name=generate_flow_name)
def my_flow(name: str):
    print(f"Running {name}")

if __name__ == "__main__":
    my_flow("example")
2. Update Work Pool Job Template: Ensure your work pool's base job template uses the flow run name provided by Prefect.
Copy code
json
{
  "variables": {},
  "job_configuration": {
    "generateName": "prefix-{{ flow_run_name }}"
  }
}
You can manage the flow name generation within the flow and Prefect will handle it during deployment. For more details on configuring work pools and job templates, you can refer to the Prefect Work Pools documentation. If you need further customization or run into specific issues, feel free to check out Prefect's GitHub issues for community and official responses: https://github.com/PrefectHQ/prefect.