yuqian90 commented on a change in pull request #14416:
URL: https://github.com/apache/airflow/pull/14416#discussion_r582548614



##########
File path: tests/models/test_taskinstance.py
##########
@@ -1488,6 +1488,30 @@ def test_previous_start_date_success(self, _, 
schedule_interval, catchup) -> Non
         assert ti_list[3].get_previous_start_date(state=State.SUCCESS) == 
ti_list[1].start_date
         assert ti_list[3].get_previous_start_date(state=State.SUCCESS) != 
ti_list[2].start_date
 
+    def test_get_previous_start_date_none(self):
+        """
+        Test that get_previous_start_date() can handle TaskInstance with no 
start_date.
+        """
+        with DAG("test_get_previous_start_date_none", start_date=DEFAULT_DATE, 
schedule_interval=None) as dag:
+            task = DummyOperator(task_id="op")
+
+        dag.create_dagrun(
+            execution_date=DEFAULT_DATE,
+            state=State.RUNNING,

Review comment:
       Hi @XD-DENG , in fact, any scenario that results in the previous 
execution_date's TaskInstance not having a `start_date` causes this crash. 
Marking the previous day's TaskInstance success is one way to run into this 
situation. There are many other ways, e.g. the DagRun for previous 
execution_date's TaskInstance has not run yet because it's still waiting for 
the scheduler to run it, or because its dependencies are not yet met). In this 
test here, the previous dagrun is created without running op, so it has no 
start_date. This triggers the bug described in the PR summary. I also updated 
the summary to include more example scenarios. 
   
   Regarding passing `start_date=None` to DagRun. I don't fully understand the 
use of `DagRun.start_date`. The issue in this PR is caused by the 
`TaskInstance` not having a `start_date`, not caused by the `DagRun` 
start_date. Maybe it's because i dont' understand how `DagRun.start_date` is 
used. Is it used to set the `TaskInstance.start_date` in some way?




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

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


Reply via email to