From d9b6ddad59c827319a1f1421bc2c99e1bc048fa5 Mon Sep 17 00:00:00 2001 From: Pankaj Koti Date: Thu, 3 Aug 2023 12:30:28 +0530 Subject: [PATCH] Use string concatenation for prepending base URL for log_url It is observed that urljoin is not yielding expected results for the task instance's log_url which needs to be a concatenation of the webserver base_url and specified relative url. The current usage of urljoin does not seem to be the right way to achieve this based on what urljoin is meant for and how it works. So, we use simple string concatenation to yield the desired result. More context in the comment https://github.com/apache/airflow/pull/31833#discussion_r1282696916 closes: #32996 --- airflow/models/taskinstance.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/airflow/models/taskinstance.py b/airflow/models/taskinstance.py index eb6388ca3d590..4012b09d2cd7c 100644 --- a/airflow/models/taskinstance.py +++ b/airflow/models/taskinstance.py @@ -33,7 +33,7 @@ from pathlib import PurePath from types import TracebackType from typing import TYPE_CHECKING, Any, Callable, Collection, Generator, Iterable, Tuple -from urllib.parse import quote, urljoin +from urllib.parse import quote import dill import jinja2 @@ -779,26 +779,28 @@ def log_url(self) -> str: """Log URL for TaskInstance.""" iso = quote(self.execution_date.isoformat()) base_url = conf.get_mandatory_value("webserver", "BASE_URL") - return urljoin( - base_url, - f"log?execution_date={iso}" + return ( + f"{base_url}" + "/log" + f"?execution_date={iso}" f"&task_id={self.task_id}" f"&dag_id={self.dag_id}" - f"&map_index={self.map_index}", + f"&map_index={self.map_index}" ) @property def mark_success_url(self) -> str: """URL to mark TI success.""" base_url = conf.get_mandatory_value("webserver", "BASE_URL") - return urljoin( - base_url, - f"confirm?task_id={self.task_id}" + return ( + f"{base_url}" + "/confirm" + f"?task_id={self.task_id}" f"&dag_id={self.dag_id}" f"&dag_run_id={quote(self.run_id)}" "&upstream=false" "&downstream=false" - "&state=success", + "&state=success" ) @provide_session