Question on state_handler, is there anyway to pass...
# prefect-community
p
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
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
I think so, do you have example of storing and retrieving parameters and secrets?
k
Should just be like:
Copy code
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:
Copy code
print(prefect.context.parameters["x"])
p
It works! Thanks!
k
Nice!