Repository: incubator-airflow Updated Branches: refs/heads/master 56501e606 -> e4494f85e
[AIRFLOW-1062] Fix DagRun#find to return correct result DagRun#find returns wrong result if external_trigger=False is specified, because adding filter is skipped on that condition. This PR fixes it. Closes #2210 from sekikn/AIRFLOW-1062 Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/e4494f85 Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/e4494f85 Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/e4494f85 Branch: refs/heads/master Commit: e4494f85ed5593c99949b52e1e0044c2a35f097f Parents: 56501e6 Author: Kengo Seki <[email protected]> Authored: Tue Apr 4 08:30:40 2017 +0200 Committer: Bolke de Bruin <[email protected]> Committed: Tue Apr 4 08:30:40 2017 +0200 ---------------------------------------------------------------------- airflow/models.py | 2 +- tests/models.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/e4494f85/airflow/models.py ---------------------------------------------------------------------- diff --git a/airflow/models.py b/airflow/models.py index 5835578..7171c05 100755 --- a/airflow/models.py +++ b/airflow/models.py @@ -3969,7 +3969,7 @@ class DagRun(Base): qry = qry.filter(DR.execution_date == execution_date) if state: qry = qry.filter(DR.state == state) - if external_trigger: + if external_trigger is not None: qry = qry.filter(DR.external_trigger == external_trigger) dr = qry.order_by(DR.execution_date).all() http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/e4494f85/tests/models.py ---------------------------------------------------------------------- diff --git a/tests/models.py b/tests/models.py index dcba354..43fccca 100644 --- a/tests/models.py +++ b/tests/models.py @@ -227,6 +227,39 @@ class DagRunTest(unittest.TestCase): 'scheduled__2015-01-02T03:04:05', run_id, 'Generated run_id did not match expectations: {0}'.format(run_id)) + def test_dagrun_find(self): + session = settings.Session() + now = datetime.datetime.now() + + dag_id1 = "test_dagrun_find_externally_triggered" + dag_run = models.DagRun( + dag_id=dag_id1, + run_id='manual__' + now.isoformat(), + execution_date=now, + start_date=now, + state=State.RUNNING, + external_trigger=True, + ) + session.add(dag_run) + + dag_id2 = "test_dagrun_find_not_externally_triggered" + dag_run = models.DagRun( + dag_id=dag_id2, + run_id='manual__' + now.isoformat(), + execution_date=now, + start_date=now, + state=State.RUNNING, + external_trigger=False, + ) + session.add(dag_run) + + session.commit() + + self.assertEqual(1, len(models.DagRun.find(dag_id=dag_id1, external_trigger=True))) + self.assertEqual(0, len(models.DagRun.find(dag_id=dag_id1, external_trigger=False))) + self.assertEqual(0, len(models.DagRun.find(dag_id=dag_id2, external_trigger=True))) + self.assertEqual(1, len(models.DagRun.find(dag_id=dag_id2, external_trigger=False))) + def test_dagrun_running_when_upstream_skipped(self): """ Tests that a DAG run is not failed when an upstream task is skipped
