@here Hi I have a query regarding context when I t...
# prefect-community
s
@here Hi I have a query regarding context when I try to use the following content in message block ,I'm seeing error "ERROR | Unexpected error occured in FlowRunner: AttributeError("'Context' object has no attribute 'task_name'") I tried to import context library as well but it is saying it is not used not sure what wrong I'm doing here Content in message block : f"The task
{prefect.context.task_name}
failed
k
Hey Sravani, no need to tag here (though I think it’s not supported anyway). We’ll respond when we see the message. Are you doing this inside a task?
s
This I'm trying in function called "post_to_slack_on_failure"
k
Could you show me some sample code?
s
k
This looks right. How do you call the function? Do you pass it as a state handler?
s
yeah
in flow
t = task(state_handlers=[post_to_slack_on_failure]) with Flow(FLOW_NAME, storage=STORAGE, state_handlers=[post_to_slack_on_failure], run_config=KubernetesRun(labels=["REGION"])) as flow:
k
This looks right. Could you give me an end to end example?
s
end to end you mean I'm trying to create a k8s job and send the notifications on task failure to slack
k
No need for the k8s part. Just a full script with flow.run that raises the error
ignore the unsed lines
k
Ah I understand. You attached the state handler to the Flow so it’s not running in a task so there is no task name.
You need to attach it to the task state handler instead
s
can you show the sample code
k
Copy code
@task(state_handlers=[mystatehandler])
Attach it there instead of the Flow
s
I think I tried that as well
let me retry
this(@task(state_handlers=[mystatehandler])) where should I put the code
k
You need to remove it from the flow side
s
if I remove from the flow side ,statehandler is not sending msg to slack channel
with Flow(FLOW_NAME, storage=STORAGE, run_config=KubernetesRun(labels=["REGION"])) as flow: