Hi Everyone, is it possible to share variables bet...
# ask-community
v
Hi Everyone, is it possible to share variables between the task and the state handlers. i want to send slack notifications based on my config parameter. the config is a dict which i want to use within the state handler post_to_slack function to send custom notifications.
k
Not really, and I think this is because the state handler might need a bit of change in design. This should be easier in Orion but in the meantime, the only way is a hack of embedding it in context.
Copy code
@task
def abc():
    prefect.context.my_var = here
or if it is returned, you can use the
state.result
. inside your state handler, you can do
prefect.context.get("my_var")
. Not that mutating context doesn’t carry over succeeding tasks
😎 1