Hi, I'm building a state handler and I'm wondering...
# ask-community
h
Hi, I'm building a state handler and I'm wondering if it's possible to attach information myself to the task, or state that will be available inside of the handler. Ideally being able to do something like this
Copy code
@task(state_handlers=[my_handler])
def my_task(my_input):
    self.message = f"Input {my_input} wasn't ok"
    assert input_is_ok(my_input)

    self.message = f"Failed to do_some_things for {my_input}"
    res = do_some_things(my_input)

    self.message = f"Failed to do_a_few_more for {my_input}"
    res2 = do_a_few_more(res)

    return res2
I understand I could use signals, using the value property of a signal to store what I want to print, but that would mean wrapping each row I'm performing an action in inside a try/except block, then raising the signal inside the except block, I've done that and it gets really cluttered I maybe missed something obvious and am going in the wrong direction though...
k
Hey @Hugo Polloli, it is not advised but if you don’t want to use the signal, you can do
prefect.context.x = 3
and then it will be available in the state handler, but probably not for downstream tasks because it’s not mutable.
h
Thanks !