airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From criccom...@apache.org
Subject [09/36] incubator-airflow git commit: [AIRFLOW-1062] Fix DagRun#find to return correct result
Date Tue, 09 May 2017 17:35:38 GMT
[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

(cherry picked from commit e4494f85ed5593c99949b52e1e0044c2a35f097f)
Signed-off-by: Bolke de Bruin <bolke@xs4all.nl>


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/010b80aa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/010b80aa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/010b80aa

Branch: refs/heads/v1-8-stable
Commit: 010b80aa8b417091705556a07d5970fe0cc4efb2
Parents: 2bebeaf
Author: Kengo Seki <sekikn@apache.org>
Authored: Tue Apr 4 08:30:40 2017 +0200
Committer: Bolke de Bruin <bolke@xs4all.nl>
Committed: Tue Apr 4 08:31:05 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/010b80aa/airflow/models.py
----------------------------------------------------------------------
diff --git a/airflow/models.py b/airflow/models.py
index fdff54e..6828ab6 100755
--- a/airflow/models.py
+++ b/airflow/models.py
@@ -3925,7 +3925,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/010b80aa/tests/models.py
----------------------------------------------------------------------
diff --git a/tests/models.py b/tests/models.py
index c63c67e..6673c04 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


Mime
View raw message