now = timezone.utcnow()
        dag_id = "test_clear_task_instances_for_backfill_dagrun"
        dag = DAG(dag_id=dag_id, start_date=now)
        dag_run = self.create_dag_run(dag, execution_date=now, is_backfill=True, state=state, session=session)
        task0 = EmptyOperator(task_id="backfill_task_0", owner="test", dag=dag)
        ti0 = TI(task=task0, run_id=dag_run.run_id)
        ti0.run()
        qry = session.query(TI).filter(TI.dag_id == dag.dag_id).all()
        clear_task_instances(qry, session)
        session.commit()
        ti0.refresh_from_db()
        dr0 = session.query(DagRun).filter(DagRun.dag_id == dag_id, DagRun.execution_date == now).first()
        assert dr0.state == DagRunState.QUEUED
    def test_dagrun_find(self, session):
        now = timezone.utcnow()
        dag_id1 = "test_dagrun_find_externally_triggered"
        dag_run = DagRun(