assert dr_database.end_date is None
        ti_op1.set_state(state=TaskInstanceState.FAILED, session=session)
        ti_op2.set_state(state=TaskInstanceState.FAILED, session=session)
        dr.update_state()
        dr_database = session.query(DagRun).filter(DagRun.run_id == "test_dagrun_update_state_end_date").one()
        assert dr_database.end_date is not None
        assert dr.end_date == dr_database.end_date
    def test_get_task_instance_on_empty_dagrun(self, session):
        """
        Make sure that a proper value is returned when a dagrun has no task instances
        """
        dag = DAG(dag_id="test_get_task_instance_on_empty_dagrun", start_date=timezone.datetime(2017, 1, 1))
        ShortCircuitOperator(task_id="test_short_circuit_false", dag=dag, python_callable=lambda: False)
        now = timezone.utcnow()
        
        
        dag_run = DagRun(
            dag_id=dag.dag_id,
            run_id="test_get_task_instance_on_empty_dagrun",
            run_type=DagRunType.MANUAL,
            execution_date=now,
            start_date=now,
            state=DagRunState.RUNNING,
            external_trigger=False,
        )
        session.add(dag_run)
        session.commit()
        ti = dag_run.get_task_instance("test_short_circuit_false")
        assert ti is None
    def test_get_latest_runs(self, session):