'Get the very latest state from the database, if a session is passed,
we use and looking up the state becomes part of the session, otherwise
a new session is used.'

@provide_session
def current_state(self, session=None):

    TI = TaskInstance
    ti = session.query(TI).filter((TI.dag_id == self.dag_id), (TI.task_id == self.task_id), (TI.execution_date == self.execution_date)).all()
    if ti:
        state = ti[0].state
    else:
        state = None
    return state
