You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/07/13 15:43:05 UTC

[GitHub] [airflow] Guilherme-B commented on issue #18116: Methods `TaskInstance.get_previous_execution_date()` & `TaskInstance.get_previous_ti()` are lying !

Guilherme-B commented on issue #18116:
URL: https://github.com/apache/airflow/issues/18116#issuecomment-1183384880

   Should anyone require, I was experiencing the same problem and this is how I approached it:
   
   ```
   @provide_session
   def get_previous_ti_by_state(task_instance: TaskInstance, task_state: TaskInstanceState, session: Session = NEW_SESSION) -> TaskInstance:
       # retrieve the latest Task Instance model whose TaskInstanceState corresponds to the specified task instance state
       return session.query(TaskInstance).filter_by(state=task_state, task_id=task_instance.task_id).order_by(TaskInstance.start_date.desc()).first()
   
   @provide_session
   def get_previous_ti_success(task_instance: TaskInstance, session: Session = NEW_SESSION) -> TaskInstance:
       return get_previous_ti_by_state(task_instance=task_instance, task_state=TaskInstanceState.SUCCESS, session=session)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org