From 9a25965da7bebe51cfe219a4870008f920370822 Mon Sep 17 00:00:00 2001 From: Kaxil Naik Date: Tue, 14 Apr 2020 22:58:47 +0100 Subject: [PATCH 1/3] Fix Extra Links in Gannt View Extra link didn't appear after changes in https://github.com/apache/airflow/pull/8220 for Gantt View --- airflow/www/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/airflow/www/views.py b/airflow/www/views.py index 8d280adbb0c6d..cc3f051b0abae 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -1961,7 +1961,10 @@ def gantt(self, session=None): # https://issues.apache.org/jira/browse/AIRFLOW-2143 try_count = ti.prev_attempted_tries gantt_bar_items.append((ti.task_id, ti.start_date, end_date, ti.state, try_count)) - tasks.append(alchemy_to_dict(ti)) + gantt_bar_items.append((ti.task_id, ti.start_date, end_date, ti.state, try_count)) + d = alchemy_to_dict(ti) + d['extraLinks'] = dag.get_task(ti.task_id).extra_links + tasks.append(d) tf_count = 0 try_count = 1 @@ -1976,10 +1979,12 @@ def gantt(self, session=None): prev_task_id = tf.task_id gantt_bar_items.append((tf.task_id, start_date, end_date, State.FAILED, try_count)) tf_count = tf_count + 1 + task = dag.get_task(tf.task_id) d = alchemy_to_dict(tf) d['state'] = State.FAILED - d['operator'] = dag.get_task(tf.task_id).task_type + d['operator'] = task.task_type d['try_number'] = try_count + d['extraLinks'] = task.extra_links tasks.append(d) data = { From 42c539c72f67e3ed7c89a7e160237ec0acd843d6 Mon Sep 17 00:00:00 2001 From: Kaxil Naik Date: Wed, 15 Apr 2020 20:24:38 +0100 Subject: [PATCH 2/3] fixup! Fix Extra Links in Gannt View --- airflow/www/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/airflow/www/views.py b/airflow/www/views.py index cc3f051b0abae..d9b060c288fef 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -1961,7 +1961,6 @@ def gantt(self, session=None): # https://issues.apache.org/jira/browse/AIRFLOW-2143 try_count = ti.prev_attempted_tries gantt_bar_items.append((ti.task_id, ti.start_date, end_date, ti.state, try_count)) - gantt_bar_items.append((ti.task_id, ti.start_date, end_date, ti.state, try_count)) d = alchemy_to_dict(ti) d['extraLinks'] = dag.get_task(ti.task_id).extra_links tasks.append(d) From 7210a9adc35069937e394ae17657f54d6d572cc7 Mon Sep 17 00:00:00 2001 From: Kaxil Naik Date: Wed, 15 Apr 2020 22:06:42 +0100 Subject: [PATCH 3/3] fixup! fixup! Fix Extra Links in Gannt View --- tests/www/test_views.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/www/test_views.py b/tests/www/test_views.py index 8f83a50f5ef94..e3f12e6e43257 100644 --- a/tests/www/test_views.py +++ b/tests/www/test_views.py @@ -2293,6 +2293,31 @@ def test_global_extra_links_works(self, get_dag_function): 'error': None }) + @mock.patch('airflow.www.views.dagbag.get_dag') + def test_extra_link_in_gantt_view(self, get_dag_function): + get_dag_function.return_value = self.dag + + exec_date = dates.days_ago(2) + start_date = datetime(2020, 4, 10, 2, 0, 0) + end_date = exec_date + timedelta(seconds=30) + + with create_session() as session: + for task in self.dag.tasks: + ti = TaskInstance(task=task, execution_date=exec_date, state="success") + ti.start_date = start_date + ti.end_date = end_date + session.add(ti) + + url = 'gantt?dag_id={}&execution_date={}'.format(self.dag.dag_id, exec_date) + resp = self.client.get(url, follow_redirects=True) + + self.check_content_in_response('"extraLinks":', resp) + + extra_links_grps = re.search(r'extraLinks\": \[(\".*?\")\]', resp.get_data(as_text=True)) + extra_links = extra_links_grps.group(0) + self.assertIn('airflow', extra_links) + self.assertIn('github', extra_links) + @mock.patch('airflow.www.views.dagbag.get_dag') def test_operator_extra_link_override_global_extra_link(self, get_dag_function): get_dag_function.return_value = self.dag