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 2021/07/30 15:25:35 UTC

[GitHub] [airflow] tsabsch commented on issue #17022: TaskInstance.previous_execution_date_success fails with: 'TaskInstance' object has no attribute 'task'

tsabsch commented on issue #17022:
URL: https://github.com/apache/airflow/issues/17022#issuecomment-889967622


   Thanks for the reply @josh-fell. Yes, I can confirm that using the context's `ti` directly works. That covers however only a subset of scenarios, because it only works for the `TaskInstance` directly associated with the operator, not the other `TaskInstance`s in the `DagRun`. In my actual use case, I want to use the code in the `on_failure_callback` to gather statistics about the `Dag`when a run fails. There, the `context["ti"]` always refers to the first `TaskInstance` in the `DagRun`.
   
   Digging a bit into the code, the difference appears to be that `dag_run.get_task_instances()` retrieves the `TaskInstance`s by a lookup from the SQL database [1], which returns only the fields defined in the SQLAlchemy model as opposed to a `TaskInstance` that was instantiated through its `__init__` [3]. I found in the class docstring, that this is a conscious design decision. In this case, I think the documentation could need some more information about the limitations of `dag_run.get_task_instances()`.
   
   [1] https://github.com/apache/airflow/blob/v1-10-stable/airflow/models/dagrun.py#L171
   [2] https://github.com/apache/airflow/blob/v1-10-stable/airflow/models/taskinstance.py#L182


-- 
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