From 0cbfa728d961965a1466353543591f9cfcf7fcb6 Mon Sep 17 00:00:00 2001 From: Alejandro Rojas Date: Wed, 26 Jun 2019 15:53:55 +0200 Subject: [PATCH 1/2] [AIRFLOW-4524] Fix incorrect field names in view for Mark Success/Failure Another mistake that wasn't caught from apache#5039 - I renamed the fields in the template (to be unique) but didn't update the view --- airflow/www/views.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/airflow/www/views.py b/airflow/www/views.py index 07335c6092581..8dc3338416214 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -1172,10 +1172,10 @@ def failed(self): execution_date = request.form.get('execution_date') confirmed = request.form.get('confirmed') == "true" - upstream = request.form.get('upstream') == "true" - downstream = request.form.get('downstream') == "true" - future = request.form.get('future') == "true" - past = request.form.get('past') == "true" + upstream = request.form.get('failed_upstream') == "true" + downstream = request.form.get('failed_downstream') == "true" + future = request.form.get('failed_future') == "true" + past = request.form.get('failed_past') == "true" return self._mark_task_instance_state(dag_id, task_id, origin, execution_date, confirmed, upstream, downstream, @@ -1192,10 +1192,10 @@ def success(self): execution_date = request.form.get('execution_date') confirmed = request.form.get('confirmed') == "true" - upstream = request.form.get('upstream') == "true" - downstream = request.form.get('downstream') == "true" - future = request.form.get('future') == "true" - past = request.form.get('past') == "true" + upstream = request.form.get('success_upstream') == "true" + downstream = request.form.get('success_downstream') == "true" + future = request.form.get('success_future') == "true" + past = request.form.get('success_past') == "true" return self._mark_task_instance_state(dag_id, task_id, origin, execution_date, confirmed, upstream, downstream, From e7ded8b1e750d92d7325362efa6d91495228d64e Mon Sep 17 00:00:00 2001 From: Alejandro Rojas Date: Wed, 26 Jun 2019 15:53:55 +0200 Subject: [PATCH 2/2] [AIRFLOW-5387] Handle showPaused URL param properly --- airflow/www/utils.py | 17 +++++++++++++++-- tests/www/test_utils.py | 42 +++++++++++++++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/airflow/www/utils.py b/airflow/www/utils.py index 4902a3c1daca9..1422ac2f0187b 100644 --- a/airflow/www/utils.py +++ b/airflow/www/utils.py @@ -65,13 +65,26 @@ def should_hide_value_for_key(key_name): def get_params(**kwargs): + hide_paused_dags_by_default = conf.getboolean('webserver', + 'hide_paused_dags_by_default') if 'showPaused' in kwargs: - v = kwargs['showPaused'] - if v or v is None: + show_paused_dags_url_param = kwargs['showPaused'] + if _should_remove_show_paused_from_url_params( + show_paused_dags_url_param, + hide_paused_dags_by_default + ): kwargs.pop('showPaused') return urlencode({d: v if v is not None else '' for d, v in kwargs.items()}) +def _should_remove_show_paused_from_url_params(show_paused_dags_url_param, + hide_paused_dags_by_default): + return any([ + show_paused_dags_url_param != hide_paused_dags_by_default, + show_paused_dags_url_param is None + ]) + + def generate_pages(current_page, num_of_pages, search=None, showPaused=None, window=7): """ diff --git a/tests/www/test_utils.py b/tests/www/test_utils.py index 002d19eda03b6..a5e519b8ec775 100644 --- a/tests/www/test_utils.py +++ b/tests/www/test_utils.py @@ -23,8 +23,10 @@ from urllib.parse import parse_qs from bs4 import BeautifulSoup +from parameterized import parameterized from airflow.www import utils +from tests.test_utils.config import conf_vars class TestUtils(unittest.TestCase): @@ -103,14 +105,38 @@ def test_params_search(self): self.assertEqual('search=bash_', utils.get_params(search='bash_')) - def test_params_showPaused_true(self): - """Should detect True as default for showPaused""" - self.assertEqual('', - utils.get_params(showPaused=True)) - - def test_params_showPaused_false(self): - self.assertEqual('showPaused=False', - utils.get_params(showPaused=False)) + @parameterized.expand([ + (True, False, ''), + (False, True, ''), + (True, True, 'showPaused=True'), + (False, False, 'showPaused=False'), + (None, True, ''), + (None, False, ''), + ]) + def test_params_showPaused(self, show_paused, hide_by_default, expected_result): + with conf_vars({('webserver', 'hide_paused_dags_by_default'): str(hide_by_default)}): + self.assertEqual(expected_result, + utils.get_params(showPaused=show_paused)) + + @parameterized.expand([ + (True, False, True), + (False, True, True), + (True, True, False), + (False, False, False), + (None, True, True), + (None, False, True), + ]) + def test_should_remove_show_paused_from_url_params(self, show_paused, + hide_by_default, expected_result): + with conf_vars({('webserver', 'hide_paused_dags_by_default'): str(hide_by_default)}): + + self.assertEqual( + expected_result, + utils._should_remove_show_paused_from_url_params( + show_paused, + hide_by_default + ) + ) def test_params_none_and_zero(self): qs = utils.get_params(a=0, b=None)