Templating flow attributes

I would like to be able to change the name and local result directory of the flows I run.
I tried using the same templating patterns than used for tasks, but it doesn’t seem to work.
More precisely, I did the following (in order to organize easily the task results by flow runs):

import prefect
from prefect import Flow, task
from prefect.engine.results import LocalResult


@task
def dummy_task(n):
    return n


with Flow(
    "test-formatted-flow",
    result=LocalResult("~/.prefect/results/{flow_run_name}/")
) as flow:
    ll = [*range(4)]
    yolo = dummy_task.map(ll)
    dummy_task.map(ll, upstream_tasks=[yolo])

Instead of interpreting the template (e.g ~/.prefect/results/test-formatted-flow-nova-snake), it literally writes the files in ~/.prefect/results/{flow_run_name}.
Is there currently a way to template this result location?
I would also like to template the flow run names, is that also possible?

1 Like

Can you try specifying this on your task decorator instead?

e.g. running:

from prefect import Flow, task
from prefect.engine.results import LocalResult

@task(result=LocalResult(dir='~/Desktop/HelloWorld/results'))
def my_task():
    return 3

with Flow("test-formatted-flow") as flow:
    first_result  = my_task()

state = flow.run()

should result in a file:

/Users/you/Desktop/HelloWorld/results/prefect-result-2022-xxxxxxx

it is, check the resources and examples here Topics tagged flow_run_name