prefect icon indicating copy to clipboard operation
prefect copied to clipboard

task_run_name does not work

Open OlegInsait opened this issue 1 year ago • 1 comments

First check

  • [X] I added a descriptive title to this issue.
  • [X] I used the GitHub search to find a similar issue and didn't find it.
  • [X] I searched the Prefect documentation for this issue.
  • [X] I checked that this issue is related to Prefect and not one of its dependencies.

Bug summary

I tried to make my task names more descriptive using task_run_name option but it did not do any changes. To understand where the problem is I tried to run the toy example from the prefect documentation but it also did not work as expected...

Reproduction

import datetime
from prefect import flow, task

@task(name="My Example Task", 
      description="An example task for a tutorial.",
      task_run_name="hello-{name}-on-{date:%A}")
def my_task(name, date):
    pass

@flow
def my_flow():
    # creates a run with a name like "hello-marvin-on-Thursday"
    my_task(name="marvin", date=datetime.datetime.now(datetime.timezone.utc))

if __name__ == "__main__":
    my_flow()

Error

18:17:13.810 | INFO    | prefect.engine - Created flow run 'lurking-termite' for flow 'my-flow'
18:17:13.812 | INFO    | Flow run 'lurking-termite' - View at http://127.0.0.1:4200/flow-runs/flow-run/c4f42cbe-41ac-42cc-b6a8-6b4cd5364879
18:17:13.890 | INFO    | Flow run 'lurking-termite' - Created task run 'My Example Task-0' for task 'My Example Task'
18:17:13.891 | INFO    | Flow run 'lurking-termite' - Executing 'My Example Task-0' immediately...
18:17:13.952 | INFO    | Task run 'hello-marvin-on-Thursday' - Finished in state Completed()
18:17:13.969 | INFO    | Flow run 'lurking-termite' - Finished in state Completed('All states completed.')

Versions (prefect version output)

Version:             2.19.4
API version:         0.8.4
Python version:      3.10.11
Git commit:          867543a8
Built:               Tue, Jun 4, 2024 3:14 PM
OS/Arch:             darwin/arm64
Profile:             default
Server type:         server

Additional context

No response

OlegInsait avatar Jun 27 '24 15:06 OlegInsait

Hi @OlegInsait! Thanks for the issue. I'm having trouble reproducing this with your MRE (or perhaps I am misunderstanding your issue?).

I'm running on Prefect 2.19.6 (and also checked on Prefect 3) and I see the following task run name in the UI:

Image

Could you try upgrading and see if things work as you expect? Or could you give more detail about what you are seeing and what you expect to see? Thank you!

zhen0 avatar Jun 27 '24 18:06 zhen0

@zhen0 Thank you for the response. I updated the prefect version to 2.19.6 as you suggested and got still the same results. Since I usually did not use UI, the problem was seen in the logs. This time I decided to go to the prefect UI and see what happens there. Now it is even more frustrating: the task name in the flow run timeline chart is indeed customized, but logs are still untouched... image

OlegInsait avatar Jun 30 '24 09:06 OlegInsait

Ah! That is odd but I can reproduce the logs vs timeline difference in 2.19.6. In Prefect 3 the logs are also updated (as in my screenshot). I'll add to our backlog and if this is important to you and you are ok with using a release candidate, you can try this out with 3.0.

zhen0 avatar Jul 01 '24 08:07 zhen0

Thank you @zhen0 ! I don't think we are ready to change prefect major version in our production, yet... Meanwhile I will use this:

from prefect import task

def my_task(arg):
    ...

task(lambda: my_task(my_arg)).with_options(name="my_fancy_name")

OlegInsait avatar Jul 01 '24 08:07 OlegInsait

Totally fair!! Thanks for sharing the workaround. That'll be helpful to others who see this issue.

zhen0 avatar Jul 01 '24 09:07 zhen0