Skip to content

Commit

Permalink
Use string concatenation for prepending base URL for log_url (#33063)
Browse files Browse the repository at this point in the history
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 apache/airflow#31833 (comment)

closes: #32996
(cherry picked from commit baa1bc0438baa05d358b236eec3c343438d8d53c)
GitOrigin-RevId: 868d1389461822cf5d54faaff3ce19913fc7f08e
  • Loading branch information
pankajkoti authored and Cloud Composer Team committed May 15, 2024
1 parent eb7a746 commit 8bc4af9
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8bc4af9

Please sign in to comment.