This is an automated email from the ASF dual-hosted git repository.

jedcunningham pushed a commit to branch v2-9-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 7cd311dc78a82c057b971912fdb4d70457e06638
Author: Madison Swain-Bowden <[email protected]>
AuthorDate: Wed Apr 24 09:41:43 2024 -0700

    Use grid view for Task Instance's `log_url` (#39183)
    
    * Use grid view for Task Instance's `log_url`
    
    * Update other tests
    
    (cherry picked from commit 6db6fef357f2adadf94956238fd14eb34aebfe34)
---
 airflow/models/taskinstance.py                  | 10 ++++++----
 tests/models/test_taskinstance.py               |  9 +++++----
 tests/providers/smtp/notifications/test_smtp.py |  2 +-
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/airflow/models/taskinstance.py b/airflow/models/taskinstance.py
index 88a495e9eb..42824fa586 100644
--- a/airflow/models/taskinstance.py
+++ b/airflow/models/taskinstance.py
@@ -1719,15 +1719,17 @@ class TaskInstance(Base, LoggingMixin):
     @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 120856dbbf..d1cb500dec 100644
--- a/tests/models/test_taskinstance.py
+++ b/tests/models/test_taskinstance.py
@@ -1981,14 +1981,15 @@ class TestTaskInstance:
         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 9878d99786..f1a71e2b53 100644
--- a/tests/providers/smtp/notifications/test_smtp.py
+++ b/tests/providers/smtp/notifications/test_smtp.py
@@ -129,7 +129,7 @@ class TestSmtpNotifier:
             from_email=conf.get("smtp", "smtp_mail_from"),
             to="[email protected]",
             subject="DAG dag - Task op - Run ID test in State None",
-            html_content="""<!DOCTYPE html>\n<html>\n    <head>\n        <meta 
http-equiv="Content-Type" content="text/html; charset=utf-8" />\n        <meta 
name="viewport" content="width=device-width">\n    </head>\n<body>\n    <table 
role="presentation">\n        \n        <tr>\n            <td>Run ID:</td>\n    
        <td>test</td>\n        </tr>\n        <tr>\n            <td>Try:</td>\n 
           <td>1 of 1</td>\n        </tr>\n        <tr>\n            <td>Task 
State:</td>\n     [...]
+            html_content="""<!DOCTYPE html>\n<html>\n    <head>\n        <meta 
http-equiv="Content-Type" content="text/html; charset=utf-8" />\n        <meta 
name="viewport" content="width=device-width">\n    </head>\n<body>\n    <table 
role="presentation">\n        \n        <tr>\n            <td>Run ID:</td>\n    
        <td>test</td>\n        </tr>\n        <tr>\n            <td>Try:</td>\n 
           <td>1 of 1</td>\n        </tr>\n        <tr>\n            <td>Task 
State:</td>\n     [...]
             smtp_conn_id="smtp_default",
             files=None,
             cc=None,

Reply via email to