[1/3] incubator-airflow git commit: [AIRFLOW-1017] get_task_instance shouldn't throw exception when no TI

2017-03-29 Thread criccomini
Repository: incubator-airflow
Updated Branches:
  refs/heads/v1-8-test 15600e42c -> eb12f0164


[AIRFLOW-1017] get_task_instance shouldn't throw exception when no TI

get_task_instance should return None instead of
throwing exception in the case where dagrun does not have the task
instance.

Closes #2178 from aoen/ddavydov--
one_instead_of_first_for_dagrun

(cherry picked from commit b2b9587cca9195229ab107394ad94b7702c70e37)


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

Branch: refs/heads/v1-8-test
Commit: 2106ff57056d08436d8aab87ac5601d9f554935a
Parents: 15600e4
Author: Chris Riccomini 
Authored: Wed Mar 29 14:09:56 2017 -0700
Committer: Chris Riccomini 
Committed: Wed Mar 29 14:09:56 2017 -0700

--
 airflow/models.py |  2 +-
 tests/models.py   | 26 ++
 2 files changed, 27 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/2106ff57/airflow/models.py
--
diff --git a/airflow/models.py b/airflow/models.py
index 42b8a7f..bdda701 100755
--- a/airflow/models.py
+++ b/airflow/models.py
@@ -3971,7 +3971,7 @@ class DagRun(Base):
 TI.dag_id == self.dag_id,
 TI.execution_date == self.execution_date,
 TI.task_id == task_id
-).one()
+).first()
 
 return ti
 

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/2106ff57/tests/models.py
--
diff --git a/tests/models.py b/tests/models.py
index 1fbb3e6..c63c67e 100644
--- a/tests/models.py
+++ b/tests/models.py
@@ -310,6 +310,32 @@ class DagRunTest(unittest.TestCase):
 state = dr.update_state()
 self.assertEqual(State.FAILED, state)
 
+def test_get_task_instance_on_empty_dagrun(self):
+"""
+Make sure that a proper value is returned when a dagrun has no task 
instances
+"""
+session = settings.Session()
+
+# Any dag will work for this
+dag = self.dagbag.get_dag('test_dagrun_short_circuit_false')
+now = datetime.datetime.now()
+
+# Don't use create_dagrun since it will create the task instances too 
which we
+# don't want
+dag_run = models.DagRun(
+dag_id=dag.dag_id,
+run_id='manual__' + now.isoformat(),
+execution_date=now,
+start_date=now,
+state=State.RUNNING,
+external_trigger=False,
+)
+session.add(dag_run)
+session.commit()
+
+ti = dag_run.get_task_instance('test_short_circuit_false')
+self.assertEqual(None, ti)
+
 
 class DagBagTest(unittest.TestCase):
 



incubator-airflow git commit: [AIRFLOW-1017] get_task_instance shouldn't throw exception when no TI

2017-03-22 Thread davydov
Repository: incubator-airflow
Updated Branches:
  refs/heads/master b586bd612 -> b2b9587cc


[AIRFLOW-1017] get_task_instance shouldn't throw exception when no TI

get_task_instance should return None instead of
throwing exception in the case where dagrun does not have the task
instance.

Closes #2178 from aoen/ddavydov--
one_instead_of_first_for_dagrun


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

Branch: refs/heads/master
Commit: b2b9587cca9195229ab107394ad94b7702c70e37
Parents: b586bd6
Author: Dan Davydov 
Authored: Wed Mar 22 15:24:57 2017 -0700
Committer: Dan Davydov 
Committed: Wed Mar 22 15:25:04 2017 -0700

--
 airflow/models.py |  2 +-
 tests/models.py   | 26 ++
 2 files changed, 27 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/b2b9587c/airflow/models.py
--
diff --git a/airflow/models.py b/airflow/models.py
index a7d2916..df23de2 100755
--- a/airflow/models.py
+++ b/airflow/models.py
@@ -4017,7 +4017,7 @@ class DagRun(Base):
 TI.dag_id == self.dag_id,
 TI.execution_date == self.execution_date,
 TI.task_id == task_id
-).one()
+).first()
 
 return ti
 

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/b2b9587c/tests/models.py
--
diff --git a/tests/models.py b/tests/models.py
index 8ce08eb..dcba354 100644
--- a/tests/models.py
+++ b/tests/models.py
@@ -310,6 +310,32 @@ class DagRunTest(unittest.TestCase):
 state = dr.update_state()
 self.assertEqual(State.FAILED, state)
 
+def test_get_task_instance_on_empty_dagrun(self):
+"""
+Make sure that a proper value is returned when a dagrun has no task 
instances
+"""
+session = settings.Session()
+
+# Any dag will work for this
+dag = self.dagbag.get_dag('test_dagrun_short_circuit_false')
+now = datetime.datetime.now()
+
+# Don't use create_dagrun since it will create the task instances too 
which we
+# don't want
+dag_run = models.DagRun(
+dag_id=dag.dag_id,
+run_id='manual__' + now.isoformat(),
+execution_date=now,
+start_date=now,
+state=State.RUNNING,
+external_trigger=False,
+)
+session.add(dag_run)
+session.commit()
+
+ti = dag_run.get_task_instance('test_short_circuit_false')
+self.assertEqual(None, ti)
+
 
 class DagBagTest(unittest.TestCase):