From 53a2f0fa7d618d9ac53064c1ae4d5061b3cde939 Mon Sep 17 00:00:00 2001 From: Kaxil Naik Date: Mon, 11 Jan 2021 18:35:32 +0000 Subject: [PATCH] Audit Log records View should not contain link if dag_id is None closes https://github.com/apache/airflow/issues/13602 --- airflow/www/utils.py | 2 +- tests/www/test_utils.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/airflow/www/utils.py b/airflow/www/utils.py index 2272552be52b9..d1c37f1aea7ab 100644 --- a/airflow/www/utils.py +++ b/airflow/www/utils.py @@ -288,7 +288,7 @@ def dag_link(attr): dag_id = attr.get('dag_id') execution_date = attr.get('execution_date') url = url_for('Airflow.graph', dag_id=dag_id, execution_date=execution_date) - return Markup('{}').format(url, dag_id) # noqa + return Markup('{}').format(url, dag_id) if dag_id else Markup('None') # noqa def dag_run_link(attr): diff --git a/tests/www/test_utils.py b/tests/www/test_utils.py index 86eaa70ca2f93..f21a64c247a35 100644 --- a/tests/www/test_utils.py +++ b/tests/www/test_utils.py @@ -175,6 +175,16 @@ def test_dag_link(self): self.assertIn('%3Ca%261%3E', html) self.assertNotIn('', html) + def test_dag_link_when_dag_is_none(self): + """Test that when there is no dag_id, dag_link does not contain hyperlink""" + from airflow.www.app import cached_app + + with cached_app(testing=True).test_request_context(): + html = str(utils.dag_link({})) + + self.assertIn('None', html) + self.assertNotIn('