<@ULVA73B9P> - is there anyway to inject the `slug...
# ask-marvin
k
@Marvin - is there anyway to inject the
slug
from a schedule into the flow run name of the flows triggered by that schedule?
m
thought for 1116.7 seconds
Short answer: not directly. In Prefect 3.x the schedule’s
slug
isn’t exposed to the flow-run name templating context, so you can’t reference it like
{schedule.slug}
in
flow_run_name
. Workaround that works well: - Put the slug (or any identifier you want) into a schedule-level parameter, then include that parameter in the deployment’s
flow_run_name
template. Runs created by that schedule will inherit those parameter overrides. Example
prefect.yaml
snippet:
Copy code
deployments:
- name: my-deployment
  entrypoint: flows/my_flow.py:my_flow
  flow_run_name: "{flow_name}-{parameters.schedule_slug}"
  schedules:
    - cron: "0 12 * * *"
      timezone: "UTC"
      slug: "noon"
      parameters:
        schedule_slug: "noon"
    - cron: "0 0 * * *"
      timezone: "UTC"
      slug: "midnight"
      parameters:
        schedule_slug: "midnight"
Alternative options: - If you trigger runs programmatically (instead of via the scheduler), you can set the name at creation time, e.g. pass
flow_run_name=
to `run_deployment(...)`: run_deployment API - If you really want the slug in the name without parameters, create separate deployments per schedule and bake the identifier into each deployment’s
flow_run_name
. It’s more overhead than the parameter approach, though. Docs for reference: - Schedules in Prefect 3: Schedules - Creating schedules on deployments: Create deployment schedules - prefect.yaml guide: prefect.yaml If you share how you’re defining your deployment (prefect.yaml vs Python), I can tailor an exact example for your setup.