ashb commented on a change in pull request #15397:
URL: https://github.com/apache/airflow/pull/15397#discussion_r644651444



##########
File path: airflow/ti_deps/deps/prev_dagrun_dep.py
##########
@@ -44,25 +44,16 @@ def _get_dep_statuses(self, ti, session, dep_context):
             return
 
         # Don't depend on the previous task instance if we are the first task
-        dag = ti.task.dag
-        if dag.catchup:
-            if dag.previous_schedule(ti.execution_date) is None:
-                yield self._passing_status(reason="This task does not have a 
schedule or is @once")
-                return
-            if dag.previous_schedule(ti.execution_date) < ti.task.start_date:
-                yield self._passing_status(
-                    reason="This task instance was the first task instance for 
its task."
-                )
-                return
+        dr = ti.get_dagrun(session=session)
+        if not dr:
+            last_dagrun = None
+        elif ti.task.dag.catchup:
+            last_dagrun = dr.get_previous_scheduled_dagrun(session)
         else:
-            dr = ti.get_dagrun(session=session)
-            last_dagrun = dr.get_previous_dagrun(session=session) if dr else 
None
-
-            if not last_dagrun:
-                yield self._passing_status(
-                    reason="This task instance was the first task instance for 
its task."
-                )
-                return
+            last_dagrun = dr.get_previous_dagrun(session=session)
+        if not last_dagrun:
+            yield self._passing_status(reason="This task instance was the 
first task instance for its task.")
+            return
 
         previous_ti = ti.get_previous_ti(session=session)

Review comment:
       This should be changed to get tis from `last_dagrun`, otherwise we are 
duplicating the effort to lookup the previous dag run twice.




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