This is an automated email from the ASF dual-hosted git repository. pankajkoti 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 dd10f472c5 DatabricksPlugin - Fix dag view redirect URL by using url_for redirect (#41040) dd10f472c5 is described below commit dd10f472c540d7f726415940d66ee4762aeffba5 Author: Pankaj Koti <pankajkoti...@gmail.com> AuthorDate: Fri Jul 26 17:50:22 2024 +0530 DatabricksPlugin - Fix dag view redirect URL by using url_for redirect (#41040) We observed that the redirect does not work well on deployments that are not rooted at "/". Following the pattern of using the flask helper url_for in our other views, it resolves this issue and redirects to the dag view page now work well with this fix. --- airflow/providers/databricks/plugins/databricks_workflow.py | 8 +++----- .../databricks/plugins/test_databricks_workflow.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/airflow/providers/databricks/plugins/databricks_workflow.py b/airflow/providers/databricks/plugins/databricks_workflow.py index 41c7b67357..be2eaecfe3 100644 --- a/airflow/providers/databricks/plugins/databricks_workflow.py +++ b/airflow/providers/databricks/plugins/databricks_workflow.py @@ -26,7 +26,6 @@ from flask import current_app, flash, redirect, request, url_for from flask_appbuilder.api import expose from packaging.version import Version -from airflow.configuration import conf from airflow.exceptions import AirflowException, TaskInstanceNotFound from airflow.models import BaseOperator, BaseOperatorLink from airflow.models.dag import DAG, clear_task_instances @@ -413,8 +412,7 @@ class RepairDatabricksTasks(AirflowBaseView, LoggingMixin): @expose("/repair_databricks_job/<string:dag_id>/<string:run_id>", methods=("GET",)) @get_auth_decorator() def repair(self, dag_id: str, run_id: str): - view = conf.get("webserver", "dag_default_view") - return_url = self._get_return_url(dag_id, view) + return_url = self._get_return_url(dag_id, run_id) tasks_to_repair = request.values.get("tasks_to_repair") self.log.info("Tasks to repair: %s", tasks_to_repair) @@ -450,8 +448,8 @@ class RepairDatabricksTasks(AirflowBaseView, LoggingMixin): return redirect(return_url) @staticmethod - def _get_return_url(dag_id: str, view) -> str: - return f"/dags/{dag_id}/{view}" + def _get_return_url(dag_id: str, run_id: str) -> str: + return url_for("Airflow.grid", dag_id=dag_id, dag_run_id=run_id) repair_databricks_view = RepairDatabricksTasks() diff --git a/tests/providers/databricks/plugins/test_databricks_workflow.py b/tests/providers/databricks/plugins/test_databricks_workflow.py index ad14be2bd5..c90caaceee 100644 --- a/tests/providers/databricks/plugins/test_databricks_workflow.py +++ b/tests/providers/databricks/plugins/test_databricks_workflow.py @@ -20,6 +20,7 @@ from __future__ import annotations from unittest.mock import MagicMock, Mock, patch import pytest +from flask import url_for from airflow.exceptions import AirflowException from airflow.models.dagrun import DagRun @@ -144,6 +145,18 @@ def test_get_task_instance(app): assert result == dag_run +@pytest.mark.db_test +def test_get_return_url_dag_id_run_id(app): + dag_id = "example_dag" + run_id = "example_run" + + expected_url = url_for("Airflow.grid", dag_id=dag_id, dag_run_id=run_id) + + with app.app_context(): + actual_url = RepairDatabricksTasks._get_return_url(dag_id, run_id) + assert actual_url == expected_url, f"Expected {expected_url}, got {actual_url}" + + @pytest.mark.db_test def test_workflow_job_run_link(app): with app.app_context():