Hi everyone — I’m trying to use the compiled “task...
# ask-community
b
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
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)
b
aah that’s great! Gonna try that, thanks!