Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 35366200C3F for ; Wed, 22 Mar 2017 23:26:24 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 33C03160B86; Wed, 22 Mar 2017 22:26:24 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7AF07160B74 for ; Wed, 22 Mar 2017 23:26:23 +0100 (CET) Received: (qmail 92118 invoked by uid 500); 22 Mar 2017 22:26:22 -0000 Mailing-List: contact commits-help@airflow.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airflow.incubator.apache.org Delivered-To: mailing list commits@airflow.incubator.apache.org Received: (qmail 92103 invoked by uid 99); 22 Mar 2017 22:26:22 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Mar 2017 22:26:22 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 06C9218033C for ; Wed, 22 Mar 2017 22:26:22 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.569 X-Spam-Level: X-Spam-Status: No, score=-3.569 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_NEUTRAL=0.652] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 1KAe2cIFhtDz for ; Wed, 22 Mar 2017 22:26:19 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 032CC5FCBA for ; Wed, 22 Mar 2017 22:26:18 +0000 (UTC) Received: (qmail 91697 invoked by uid 99); 22 Mar 2017 22:26:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Mar 2017 22:26:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 06DF4DFB0E; Wed, 22 Mar 2017 22:26:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davydov@apache.org To: commits@airflow.incubator.apache.org Message-Id: <97baa1649d324b8a988200e82b6eb894@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-airflow git commit: [AIRFLOW-1017] get_task_instance shouldn't throw exception when no TI Date: Wed, 22 Mar 2017 22:26:17 +0000 (UTC) archived-at: Wed, 22 Mar 2017 22:26:24 -0000 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):