Skip to content

Commit

Permalink
Fix bug introduced by replacing spaces by + in run_id (#36877)
Browse files Browse the repository at this point in the history
While working on sanitizing the run_id(#32293), I replaced spaces with +
which is not an ideal way to quote a URL. This led to issues when users
use spaces in their DAG run_id.
This commit fixes the issue by using urllib.parse.quote to properly quote
the URL.

(cherry picked from commit ec8fab5)
  • Loading branch information
ephraimbuddy committed Feb 22, 2024
1 parent a6055e7 commit a2d6e6e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,7 @@ def delete(self):
@provide_session
def trigger(self, dag_id: str, session: Session = NEW_SESSION):
"""Triggers DAG Run."""
run_id = request.values.get("run_id", "").replace(" ", "+")
run_id = request.values.get("run_id", "")
origin = get_safe_url(request.values.get("origin"))
unpause = request.values.get("unpause")
request_conf = request.values.get("conf")
Expand Down
2 changes: 2 additions & 0 deletions tests/www/views/test_views_trigger_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import datetime
import json
from urllib.parse import quote

import pytest

Expand Down Expand Up @@ -369,6 +370,7 @@ def test_trigger_dag_params_array_value_none_render(admin_client, dag_maker, ses
def test_dag_run_id_pattern(session, admin_client, pattern, run_id, result):
with conf_vars({("scheduler", "allowed_run_id_pattern"): pattern}):
test_dag_id = "example_bash_operator"
run_id = quote(run_id)
admin_client.post(f"dags/{test_dag_id}/trigger?run_id={run_id}", data={"conf": "{}"})
run = session.query(DagRun).filter(DagRun.dag_id == test_dag_id).first()
if result:
Expand Down

0 comments on commit a2d6e6e

Please sign in to comment.