https://prefect.io logo
Title
p

Patrick Tan

04/15/2022, 2:09 PM
Question on state_handler, is there anyway to pass arguments to state_handler? I want to update database table when flow or task fails. The arguments are database config information and credentials
k

Kevin Kho

04/15/2022, 2:18 PM
Not really.. You’d have to pull them from somewhere else. If they are secrets though, they might be available in
prefect.context.secrets
, parameters will be in
prefect.context.parameters
so you can pull those inside a state handler. Would that help you?
p

Patrick Tan

04/15/2022, 2:20 PM
I think so, do you have example of storing and retrieving parameters and secrets?
k

Kevin Kho

04/15/2022, 2:23 PM
Should just be like:
def mystatehandler(obj, old_state, new_state):
    print(prefect.context.parameters)
    print(prefect.context.secrets)
    Secret("name").get()
and parameters is a dict. I think secrets might be a list (not super sure). But you can also pull a secret if you know the name with
Secret.get()
So you can do:
print(prefect.context.parameters["x"])
p

Patrick Tan

04/15/2022, 3:44 PM
It works! Thanks!
k

Kevin Kho

04/15/2022, 3:44 PM
Nice!