dstandish commented on a change in pull request #5372: [AIRFLOW-3057] add 
prev_*_date_success to template context
URL: https://github.com/apache/airflow/pull/5372#discussion_r291071277
 
 

 ##########
 File path: tests/models/test_taskinstance.py
 ##########
 @@ -992,3 +994,103 @@ def success_handler(self, context):
         self.assertEqual(cw.task_state_in_callback, State.RUNNING)
         ti.refresh_from_db()
         self.assertEqual(ti.state, State.SUCCESS)
+
+    def _test_previous_dates(self, schedule_interval: Union[str, 
datetime.timedelta, None], catchup: bool,
+                             object_: str) -> None:
+        dag_id = 'test_previous_dates'
+        dag = models.DAG(dag_id=dag_id, schedule_interval=schedule_interval, 
catchup=catchup)
+        task = DummyOperator(task_id='task', dag=dag, start_date=DEFAULT_DATE)
+
+        d1 = '2019-01-01T00:00:00+00:00'
+        d2 = '2019-01-02T00:00:00+00:00'
+        d3 = '2019-01-03T00:00:00+00:00'
+
+        with create_session() as session:  # type: Session
+
+            # session.query(DagRun).all().filter(DagRun.dag_id == dag_id).all()
+            # session.query(TI).filter(TI.dag_id == dag_id).delete()
+            # session.commit()
+            dag.create_dagrun(
+                run_id='scheduled__{}'.format(d1),
+                state=State.SUCCESS,
+                execution_date=pendulum.parse(d1),
+                start_date=pendulum.utcnow(),
+                session=session
+            )
+
+            dag.create_dagrun(
+                run_id='scheduled__{}'.format(d2),
+                state=State.FAILED,
+                execution_date=pendulum.parse(d2),
+                start_date=pendulum.utcnow(),
+                session=session
+            )
+
+            dag.create_dagrun(
+                run_id='scheduled__{}'.format(d3),
+                state=State.SUCCESS,
+                execution_date=pendulum.parse(d3),
+                start_date=pendulum.utcnow(),
+                session=session
+            )
+
+            t1 = TI(task=task, execution_date=pendulum.parse(d1))
+            t1.set_state(state=State.SUCCESS, session=session)
+
+            t2 = TI(task=task, execution_date=pendulum.parse(d2))
+            t2.set_state(state=State.SUCCESS, session=session)
+
+            t3 = TI(task=task, execution_date=pendulum.parse(d3))
+            t3.set_state(state=State.SUCCESS, session=session)
+
+            if object_ == 'previous_ti':
+                self.assertIsNone(t1.previous_ti)
+                assert isinstance(t3.previous_ti, TI)  # mypy
 
 Review comment:
   Similar to above... because previous_ti can return `None` or `TI`, mypy 
apparently assumes that `None` should have `execution_date` attribute, since it 
is called in the next line.  It doesn't, so it failed.  The assert apparently 
tells mypy "in this situation, `previous_ti` will not be `None` so don't worry 
bout it".

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


With regards,
Apache Git Services

Reply via email to