Hi everyone — I’m trying to use the compiled “task run name” on my custom state handler, but I’m struggling to find it on the “obj”. Does anyone know if that’s possible?
z
Zach Angell
07/09/2021, 1:19 PM
Hi @Bruno Murino there's currently an open enhancement request to have the task run name in context. https://github.com/PrefectHQ/prefect/issues/4716
Until then, I'd recommend using the task run id to query the graphql api to get the task run name
in your state handler, you can do something like
Copy code
import prefect
from prefect.client import Client
# get the task run id from context
task_run_id = prefect.context.get("task_run_id")
# query for the name
query = """
query {task_run_by_pk (id: <task_run_id>) {
name
}}
"""
Client().graphql(query)
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.