cansjt opened a new issue #18116:
URL: https://github.com/apache/airflow/issues/18116


   ### Apache Airflow version
   
   2.1.3 (latest released)
   
   ### Operating System
   
   Linux
   
   ### Versions of Apache Airflow Providers
   
   Irrelevant
   
   ### Deployment
   
   Other
   
   ### Deployment details
   
   Irrelevant
   
   ### What happened
   
   The method `TaskInstance.get_previous_execution_date()` asks a state, which 
logically means you should get as a return value the execution date of the same 
tasks, with the given state.
   
   But in truth it is not the tasks state that is looked, but the [previous 
DagRun 
state](https://github.com/apache/airflow/blob/ebbe2b4cafebe2b523ca08abd40145c3c7eec046/airflow/models/taskinstance.py#L916).
 Which means that, for example, using the method to determine when was the last 
time when the task was not skipped, you get the wrong date in return as the 
actual tasks states are disregarded.
   
   The behaviour is not only unexpected, but undocumented as the method 
documentation refers the reader to a now deprecated and undocumented method, 
which refers you to the documentation of yet another method 
[`get_previous_ti()`](https://github.com/apache/airflow/blob/ebbe2b4cafebe2b523ca08abd40145c3c7eec046/airflow/models/taskinstance.py#L913)
 which states:
   
   > The task instance for the task that ran before this task instance.
   > :param state: If passed, it only take into account instances of a specific 
state.
   
   Given that this is a method of the TaskInstance class, that returns yet 
another TaskInstance instance, I don't see why the users of this method should 
not assume it is the state of tasks instance that is being considered in the 
method implementation. Yet it is not, it is the DagRun state that is.
   
   ### What you expected to happen
   
   I'd expect the method to return me the  task instance (or its execution 
date, depending on the method) that is in the state I gave, not any instance 
possibly not in the state I specified.
   
   ### How to reproduce
   
   Create a DAG with one task
   Create two DagRun for the dag the first shoud complete, the second should be 
skipped.
   Create a third dag run that looks for the last task in the SUCCESS state. 
You will not get the (execution date of the) task from the first dag run, but 
from the second dag run.
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to