https://prefect.io logo
#prefect-community
Title
# prefect-community
p

philip

06/01/2020, 9:09 AM
I want to get my Parameter at state_handler, It is OK on local test. But it have error on prefect server like this:
Exception raised while calling state handlers: KeyError(<Parameter: fisrt_num>,)
how can i solve this problem? Here is my code
Copy code
@task
def add(x, y):
    return x+y

def post_to_slack(task, old_state, new_state):
    if new_state.is_failed():
        msg = "Task {0} finished in state {1}".format(task, new_state)
        
    if new_state.is_finished():
        p = new_state.result[num].result
        print(p)
        
    return new_state

with Flow("Tutorial", state_handlers=[post_to_slack]) as flow:
    x = Parameter("fisrt_num")
    y = Parameter("Second_num")

    num = add(x,y)
c

Chris White

06/01/2020, 2:52 PM
Hi @philip - there are a few things: - your flow doesn’t have any tasks in it; you probably intended to add those Parameters to your Flow but you didn’t. This is a common confusion - checkout GitHub for solutions - I don’t recommend referencing
x
within your State Handler; this relies on the statehandler being run in the same process that you created
x
and could lead to unexpected errors
p

philip

06/01/2020, 3:50 PM
Thank you, I edited some my code. This is an example, I want to use state handler to check if the process finished, i can print some log or send email. Can i referencing like
num
in handler?
2 Views