-
Notifications
You must be signed in to change notification settings - Fork 16.6k
[AIRFLOW-4549] skipped tasks should be ok for wait_for_downstream #5308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5308c63
c50d48b
9619a9f
75aef23
a2095af
27a5523
36b387a
5702b08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from datetime import datetime | ||
|
|
||
| from airflow.models import DAG | ||
| from airflow.operators.dummy_operator import DummyOperator | ||
|
|
||
| DEFAULT_DATE = datetime(2016, 1, 1) | ||
| default_args = dict( | ||
| start_date=DEFAULT_DATE, | ||
| owner='airflow') | ||
|
|
||
| # DAG tests depends_on_past dependencies | ||
| dag_dop = DAG(dag_id='test_depends_on_past', default_args=default_args) | ||
| dag_dop_task1 = DummyOperator( | ||
| task_id='test_dop_task', | ||
| dag=dag_dop, | ||
| depends_on_past=True,) | ||
|
|
||
|
|
||
| dag_wfd = DAG(dag_id='test_wait_for_downstream', default_args=default_args) | ||
| upstream_task = DummyOperator( | ||
| task_id='upstream_task', | ||
| dag=dag_wfd, | ||
| wait_for_downstream=True, | ||
| ) | ||
| downstream_task = DummyOperator( | ||
| task_id='downstream_task', | ||
| dag=dag_wfd, | ||
| ) | ||
| upstream_task.set_downstream(downstream_task) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |||||||||||||||||
| import unittest | ||||||||||||||||||
|
|
||||||||||||||||||
| from airflow import models, settings | ||||||||||||||||||
| from airflow.exceptions import AirflowException | ||||||||||||||||||
| from airflow.models import DAG, TaskInstance as TI, clear_task_instances | ||||||||||||||||||
| from airflow.models.dagrun import DagRun | ||||||||||||||||||
| from airflow.operators.dummy_operator import DummyOperator | ||||||||||||||||||
|
|
@@ -29,6 +30,7 @@ | |||||||||||||||||
| from airflow.utils.trigger_rule import TriggerRule | ||||||||||||||||||
| from airflow.utils.types import DagRunType | ||||||||||||||||||
| from tests.models import DEFAULT_DATE | ||||||||||||||||||
| from tests.test_utils.mock_executor import MockExecutor | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| class TestDagRun(unittest.TestCase): | ||||||||||||||||||
|
|
@@ -559,3 +561,89 @@ def with_all_tasks_removed(dag): | |||||||||||||||||
| dagrun.verify_integrity() | ||||||||||||||||||
| flaky_ti.refresh_from_db() | ||||||||||||||||||
| self.assertEqual(State.NONE, flaky_ti.state) | ||||||||||||||||||
|
|
||||||||||||||||||
|
||||||||||||||||||
| dr.dag = dag | |
| if dag.catchup: | |
| last_dagrun = dr.get_previous_scheduled_dagrun(session=session) | |
| else: | |
| last_dagrun = dr.get_previous_dagrun(session=session) | |
| if last_dagrun: | |
| return last_dagrun.get_task_instance(self.task_id, session=session) |
I'm also not sure they're strictly necessary. I think this code is reasonably unit tested through the combination of https://github.com/apache/airflow/blob/e1c1a8dad0e01a7baa50ebe02e748429d33241fd/tests/ti_deps/deps/test_prev_dagrun_dep.py and https://github.com/apache/airflow/blob/5acc221a0993296b00430626de107515acb9c2d4/tests/models/test_taskinstance.py#L519-L545. At the same time, it might be more straightforward to follow this example in an actual Dag like here, and the task_instance.run() part of this is only tested in accidentally tangent unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this is the only line of non-test code that is changed -- the rest is either testing or documentation)