Skip to content

Commit

Permalink
Removed 'request.referrer' from views.py (#21751)
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarsharma2 authored Feb 27, 2022
1 parent 900bad1 commit df31902
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions airflow/www/templates/airflow/dag.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ <h4 class="pull-right" style="user-select: none;-moz-user-select: auto;">
<li><a href="{{ url_for('Airflow.trigger', dag_id=dag.dag_id, origin=url_for(request.endpoint, dag_id=dag.dag_id)) }}">Trigger DAG w/ config</a></li>
</ul>
</div>
<a href="{{ url_for('Airflow.delete', dag_id=dag.dag_id) }}" title="Delete&nbsp;DAG" class="btn btn-default btn-icon-only{{ ' disabled' if not dag.can_delete }}"
<a href="{{ url_for('Airflow.delete', dag_id=dag.dag_id, redirect_url=url_for(request.endpoint, dag_id=dag.dag_id)) }}" title="Delete&nbsp;DAG" class="btn btn-default btn-icon-only{{ ' disabled' if not dag.can_delete }}"
onclick="return confirmDeleteDag(this, '{{ dag.safe_dag_id }}')" aria-label="Delete DAG">
<span class="material-icons text-danger" aria-hidden="true">delete_outline</span>
</a>
Expand Down Expand Up @@ -412,7 +412,7 @@ <h4 class="modal-title" id="dagModalLabel">
</span>
</div>
<hr style="margin-bottom: 8px;">
<a id="btn_dagrun_details" class="btn" data-base-url="{{ url_for('Airflow.dagrun_details') }}">
<a id="btn_dagrun_details" class="btn" data-base-url="{{ url_for('Airflow.dagrun_details', redirect_url=request.base_url) }}">
DAG Run details
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/templates/airflow/dags.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ <h2>{{ page_title }}</h2>
</div>
{% endif %}
{# Use dag_id instead of dag.dag_id, because the DAG might not exist in the webserver's DagBag #}
<a href="{{ url_for('Airflow.delete', dag_id=dag.dag_id) }}" onclick="return confirmDeleteDag(this, '{{ dag.dag_id }}')" title="Delete&nbsp;DAG" aria-label="Delete DAG" class="btn btn-sm btn-default btn-icon-only {{ ' disabled' if not dag.can_delete }}">
<a href="{{ url_for('Airflow.delete', dag_id=dag.dag_id, redirect_url=url_for(request.endpoint)) }}" onclick="return confirmDeleteDag(this, '{{ dag.dag_id }}')" title="Delete&nbsp;DAG" aria-label="Delete DAG" class="btn btn-sm btn-default btn-icon-only {{ ' disabled' if not dag.can_delete }}">
<span class="material-icons text-danger" aria-hidden="true">delete_outline</span>
</a>
</div>
Expand Down
17 changes: 10 additions & 7 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1752,20 +1752,21 @@ def delete(self):

dag_id = request.values.get('dag_id')
origin = get_safe_url(request.values.get('origin'))
redirect_url = get_safe_url(request.values.get('redirect_url'))

try:
delete_dag.delete_dag(dag_id)
except DagNotFound:
flash(f"DAG with id {dag_id} not found. Cannot delete", 'error')
return redirect(request.referrer)
return redirect(redirect_url)
except AirflowException:
flash(
f"Cannot delete DAG with id {dag_id} because some task instances of the DAG "
"are still running. Please mark the task instances as "
"failed/succeeded before deleting the DAG",
"error",
)
return redirect(request.referrer)
return redirect(redirect_url)

flash(f"Deleting DAG with id {dag_id}. May take a couple minutes to fully disappear.")

Expand Down Expand Up @@ -2159,10 +2160,11 @@ def dagrun_details(self, session=None):
dag_run: Optional[DagRun] = (
session.query(DagRun).filter(DagRun.dag_id == dag_id, DagRun.run_id == run_id).one_or_none()
)
redirect_url = get_safe_url(request.values.get('redirect_url'))

if dag_run is None:
flash(f"No DAG run found for DAG id {dag_id} and run id {run_id}", "error")
return redirect(request.referrer or url_for('Airflow.index'))
return redirect(redirect_url or url_for('Airflow.index'))
else:
try:
duration = dag_run.end_date - dag_run.start_date
Expand Down Expand Up @@ -2238,6 +2240,7 @@ def confirm(self):
task_id = args.get('task_id')
dag_run_id = args.get('dag_run_id')
state = args.get('state')
origin = args.get('origin')

upstream = to_boolean(args.get('upstream'))
downstream = to_boolean(args.get('downstream'))
Expand All @@ -2247,13 +2250,13 @@ def confirm(self):
dag = current_app.dag_bag.get_dag(dag_id)
if not dag:
flash(f'DAG {dag_id} not found', "error")
return redirect(request.referrer or url_for('Airflow.index'))
return redirect(origin or url_for('Airflow.index'))

try:
task = dag.get_task(task_id)
except airflow.exceptions.TaskNotFound:
flash(f"Task {task_id} not found", "error")
return redirect(request.referrer or url_for('Airflow.index'))
return redirect(origin or url_for('Airflow.index'))

task.dag = dag

Expand All @@ -2262,12 +2265,12 @@ def confirm(self):
'failed',
):
flash(f"Invalid state {state}, must be either 'success' or 'failed'", "error")
return redirect(request.referrer or url_for('Airflow.index'))
return redirect(origin or url_for('Airflow.index'))

latest_execution_date = dag.get_latest_execution_date()
if not latest_execution_date:
flash(f"Cannot mark tasks as {state}, seem that dag {dag_id} has never run", "error")
return redirect(request.referrer or url_for('Airflow.index'))
return redirect(origin or url_for('Airflow.index'))

from airflow.api.common.mark_tasks import set_state

Expand Down

0 comments on commit df31902

Please sign in to comment.