PrefectHQ / prefect

Prefect is a workflow orchestration framework for building resilient data pipelines in Python.
https://prefect.io
Apache License 2.0
15.36k stars 1.51k forks source link

Custom `task_run_name` not displayed in logs #14371

Open OlegInsait opened 1 week ago

OlegInsait commented 1 week ago

First check

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

zhen0 commented 1 week ago

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!

OlegInsait commented 1 week ago

@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

zhen0 commented 1 week ago

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.

OlegInsait commented 1 week ago

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")
zhen0 commented 1 week ago

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