Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions airflow-core/src/airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ def log_url(self) -> str:
"""Log URL for TaskInstance."""
run_id = quote(self.run_id)
base_url = conf.get("api", "base_url", fallback="http://localhost:8080/")
if not base_url.endswith('/'):
base_url += '/'
map_index = f"/mapped/{self.map_index}" if self.map_index >= 0 else ""
try_number = f"?try_number={self.try_number}" if self.try_number > 0 else ""
_log_uri = f"{base_url}dags/{self.dag_id}/runs/{run_id}/tasks/{self.task_id}{map_index}{try_number}"
Expand Down
6 changes: 6 additions & 0 deletions airflow-core/tests/unit/models/test_taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
from tests_common.test_utils import db
from tests_common.test_utils.db import clear_db_connections, clear_db_runs
from tests_common.test_utils.mock_operators import MockOperator
from tests_common.test_utils.config import conf_vars
from unit.models import DEFAULT_DATE

pytestmark = [pytest.mark.db_test]
Expand Down Expand Up @@ -1558,6 +1559,11 @@ def test_log_url(self, create_task_instance):
expected_url = "http://localhost:8080/dags/my_dag/runs/test/tasks/op"
assert ti.log_url == expected_url

# Test with base_url that doesn't end with a slash
with conf_vars({('api', 'base_url'): 'http://example.com'}):
expected_url = "http://example.com/dags/my_dag/runs/test/tasks/op"
assert ti.log_url == expected_url

ti.map_index = 1
ti.try_number = 2
session = settings.Session()
Expand Down
Loading