diff --git a/airflow/models/taskinstance.py b/airflow/models/taskinstance.py index 88a495e9eb5c..42824fa58645 100644 --- a/airflow/models/taskinstance.py +++ b/airflow/models/taskinstance.py @@ -1719,15 +1719,17 @@ def generate_command( @property def log_url(self) -> str: """Log URL for TaskInstance.""" - iso = quote(self.execution_date.isoformat()) + run_id = quote(self.run_id) base_url = conf.get_mandatory_value("webserver", "BASE_URL") return ( f"{base_url}" - "/log" - f"?execution_date={iso}" + f"/dags" + f"/{self.dag_id}" + f"/grid" + f"?dag_run_id={run_id}" f"&task_id={self.task_id}" - f"&dag_id={self.dag_id}" f"&map_index={self.map_index}" + "&tab=logs" ) @property diff --git a/tests/models/test_taskinstance.py b/tests/models/test_taskinstance.py index 120856dbbfd2..d1cb500dec6c 100644 --- a/tests/models/test_taskinstance.py +++ b/tests/models/test_taskinstance.py @@ -1981,14 +1981,15 @@ def test_get_num_running_task_instances_per_dagrun(self, create_task_instance, d assert 1 == tis2[("task_3", 0)].get_num_running_task_instances(session=session, same_dagrun=True) def test_log_url(self, create_task_instance): - ti = create_task_instance(dag_id="dag", task_id="op", execution_date=timezone.datetime(2018, 1, 1)) + ti = create_task_instance(dag_id="my_dag", task_id="op", execution_date=timezone.datetime(2018, 1, 1)) expected_url = ( - "http://localhost:8080/log?" - "execution_date=2018-01-01T00%3A00%3A00%2B00%3A00" + "http://localhost:8080" + "/dags/my_dag/grid" + "?dag_run_id=test" "&task_id=op" - "&dag_id=dag" "&map_index=-1" + "&tab=logs" ) assert ti.log_url == expected_url diff --git a/tests/providers/smtp/notifications/test_smtp.py b/tests/providers/smtp/notifications/test_smtp.py index 9878d99786ad..f1a71e2b53c1 100644 --- a/tests/providers/smtp/notifications/test_smtp.py +++ b/tests/providers/smtp/notifications/test_smtp.py @@ -129,7 +129,7 @@ def test_notifier_with_defaults(self, mock_smtphook_hook, create_task_instance): from_email=conf.get("smtp", "smtp_mail_from"), to="test_reciver@test.com", subject="DAG dag - Task op - Run ID test in State None", - html_content="""\n\n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Run ID:test
Try:1 of 1
Task State:None
Host:
Log Link:http://localhost:8080/log?execution_date=2018-01-01T00%3A00%3A00%2B00%3A00&task_id=op&dag_id=dag&map_index=-1
Mark Success Link:http://localhost:8080/confirm?task_id=op&dag_id=dag&dag_run_id=test&upstream=false&downstream=false&state=success
\n\n""", + html_content="""\n\n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Run ID:test
Try:1 of 1
Task State:None
Host:
Log Link:http://localhost:8080/dags/dag/grid?dag_run_id=test&task_id=op&map_index=-1&tab=logs
Mark Success Link:http://localhost:8080/confirm?task_id=op&dag_id=dag&dag_run_id=test&upstream=false&downstream=false&state=success
\n\n""", smtp_conn_id="smtp_default", files=None, cc=None,