Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,9 @@ 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))
d = alchemy_to_dict(ti)
d['extraLinks'] = dag.get_task(ti.task_id).extra_links
tasks.append(d)

tf_count = 0
try_count = 1
Expand All @@ -1976,10 +1978,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 = {
Expand Down
25 changes: 25 additions & 0 deletions tests/www/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down