Wrong task_run_name in logging

Prefect 2.7.12 made task_run_name available, but it seems that is has no effect. Am I using it correctly?

Here’s a simple workflow.

# task_run_name_test.py
from prefect import flow, task

@task(task_run_name='say_hello-{name}')
def say_hello(name):
    print(f"Hello {name}!")

@flow
def hello_flow():
    say_hello('World')

if __name__ == '__main__':
    hello_flow()

I am executing it like that: python task_run_name_test.py

I get this output:

14:26:07.801 | INFO    | prefect.engine - Created flow run 'colossal-leech' for flow 'run_name_test'
14:26:08.045 | INFO    | Flow run 'colossal-leech' - Created task run 'say_hello-0' for task 'say_hello'
14:26:08.047 | INFO    | Flow run 'colossal-leech' - Executing 'say_hello-0' immediately...
Hello World!
14:26:08.193 | INFO    | Task run 'say_hello-World' - Finished in state Completed()
14:26:08.246 | INFO    | Flow run 'colossal-leech' - Finished in state Completed('All states completed.'

I should see say_hellow_World, but I get say_hello-0 for task name. Is that a bug?

The task run name is correctly being renamed when execution is triggered for it. I reran your code with debug logs enabled, initially prior to execution a place holder would exist for parameterized names.

15:15:19.314 | DEBUG   | Flow run 'devious-bullfrog' - Beginning execution...
15:15:19.575 | INFO    | Flow run 'devious-bullfrog' - Created task run 'say_hello-0' for task 'say_hello'
15:15:19.576 | INFO    | Flow run 'devious-bullfrog' - Executing 'say_hello-0' immediately...
15:15:20.971 | DEBUG   | Task run 'say_hello-World' - Renamed task run 'say_hello-0' to 'say_hello-World'
15:15:20.971 | DEBUG   | Task run 'say_hello-World' - Beginning execution...
Hello World!
15:15:21.233 | INFO    | Task run 'say_hello-World' - Finished in state Completed()

I can see it now, but I don’t understand why it gets renamed so late and not instantiated with that name. This way it misses the point of calling it somehow, that is you could track the execution of something from beginning to end. Now you have to track 2 names.