This is an automated email from the ASF dual-hosted git repository.
eladkal pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new baa1bc0438 Use string concatenation for prepending base URL for
log_url (#33063)
baa1bc0438 is described below
commit baa1bc0438baa05d358b236eec3c343438d8d53c
Author: Pankaj Koti <[email protected]>
AuthorDate: Thu Aug 3 14:49:21 2023 +0530
Use string concatenation for prepending base URL for log_url (#33063)
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 eb6388ca3d..4012b09d2c 100644
--- a/airflow/models/taskinstance.py
+++ b/airflow/models/taskinstance.py
@@ -33,7 +33,7 @@ from functools import partial
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 @@ class TaskInstance(Base, LoggingMixin):
"""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