i

    itay livni

    2 years ago
    Hi - I am trying to piece together a state handler that handles a
    task
    failing and returns a success and sets the final result to a
    None
    type or
    df
    . Can you point me to the specific pattern to copy? Thamks
    j

    josh

    2 years ago
    Hey @itay livni I believe you’re going to want to do something like this:
    def handle_disambig_error(task, old_state, new_state):
        if new_state.is_failed():
            # do your state logic here
        return new_state
    The signature takes in the old state and the new state. e.g. signature:
    def state_handler(obj: Union[Task, Flow], old_state: State, new_state: State) -> Optional[State]:
        """
        Any function with this signature can serve as a state handler.
    
        Args:
            - obj (Union[Task, Flow]): the underlying object to which this state handler
                is attached
            - old_state (State): the previous state of this object
            - new_state (State): the proposed new state of this object
    
        Returns:
            - Optional[State]: the new state of this object (typically this is just `new_state`)
        """
        pass
    i

    itay livni

    2 years ago
    Thanks
    https://stackoverflow.com/questions/59954398/how-to-handle-a-task-failure-in-prefect-and-return-success-with-the-on-failure-p @josh @Chris White I dont have enough points for a prefect tag on stack. Can someone add it please. It would be useful (IMO)