This is an automated email from the ASF dual-hosted git repository.
jscheffl 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 f5d802791f Change Trigger UI to use HTTP POST in web ui (#36026)
f5d802791f is described below
commit f5d802791fa5f6b13b635f06a1ea2eccc22a9ba7
Author: Jens Scheffler <[email protected]>
AuthorDate: Sun Dec 3 00:38:20 2023 +0100
Change Trigger UI to use HTTP POST in web ui (#36026)
* Change Trigger UI to use HTTP POST in web ui, GET always shows trigger
form
* Adjust tests to changed behavior of trigger handling, expects data
submitted in POST
---
airflow/www/templates/airflow/dag.html | 7 ++++++-
airflow/www/templates/airflow/dags.html | 7 ++++++-
airflow/www/views.py | 4 +++-
tests/www/views/test_views_trigger_dag.py | 20 ++++++++++++++------
4 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/airflow/www/templates/airflow/dag.html
b/airflow/www/templates/airflow/dag.html
index 40440d3fd6..435dacb50c 100644
--- a/airflow/www/templates/airflow/dag.html
+++ b/airflow/www/templates/airflow/dag.html
@@ -254,7 +254,7 @@
{% else %}
<a href="{{ url_for('Airflow.trigger', dag_id=dag.dag_id,
origin=url_for(request.endpoint, dag_id=dag.dag_id, **request.args)) }}"
{% endif %}
- title="Trigger DAG"
+ onclick="return triggerDag(this, '{{ dag.dag_id }}')"
title="Trigger DAG"
aria-label="Trigger DAG"
class="btn btn-default btn-icon-only{{ ' disabled' if not
dag.can_trigger }} trigger-dropdown-btn">
<span class="material-icons" aria-hidden="true">play_arrow</span>
@@ -289,5 +289,10 @@
}
return false;
}
+
+ function triggerDag(link, dagId) {
+ postAsForm(link.href, {});
+ return false;
+ }
</script>
{% endblock %}
diff --git a/airflow/www/templates/airflow/dags.html
b/airflow/www/templates/airflow/dags.html
index c2ccb03e5d..1ee168996c 100644
--- a/airflow/www/templates/airflow/dags.html
+++ b/airflow/www/templates/airflow/dags.html
@@ -385,7 +385,7 @@
</div>
{% else %}
<a href="{{ url_for('Airflow.trigger', dag_id=dag.dag_id,
redirect_url=url_for(request.endpoint)) }}"
- title="Trigger DAG"
+ onclick="return triggerDag(this, '{{ dag.dag_id }}')"
title="Trigger DAG"
aria-label="Trigger DAG"
class="btn btn-sm btn-default btn-icon-only{{ ' disabled'
if not dag.can_trigger }} trigger-dropdown-btn">
<span class="material-icons"
aria-hidden="true">play_arrow</span>
@@ -483,5 +483,10 @@
}
return false;
}
+
+ function triggerDag(link, dagId) {
+ postAsForm(link.href, {});
+ return false;
+ }
</script>
{% endblock %}
diff --git a/airflow/www/views.py b/airflow/www/views.py
index 649440865c..c4230c1900 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -2047,7 +2047,9 @@ class Airflow(AirflowBaseView):
if isinstance(run_conf, dict) and any(run_conf)
}
- if request.method == "GET" and (ui_fields_defined or
show_trigger_form_if_no_params):
+ if request.method == "GET" or (
+ not request_conf and (ui_fields_defined or
show_trigger_form_if_no_params)
+ ):
# Populate conf textarea with conf requests parameter, or
dag.params
default_conf = ""
diff --git a/tests/www/views/test_views_trigger_dag.py
b/tests/www/views/test_views_trigger_dag.py
index 65ad8734d5..6471c092bd 100644
--- a/tests/www/views/test_views_trigger_dag.py
+++ b/tests/www/views/test_views_trigger_dag.py
@@ -57,7 +57,7 @@ def test_trigger_dag_button_normal_exist(admin_client):
)
def test_trigger_dag_button(admin_client, req, expected_run_id):
test_dag_id = "example_bash_operator"
- admin_client.post(f"dags/{test_dag_id}/trigger?{req}")
+ admin_client.post(f"dags/{test_dag_id}/trigger?{req}", data={"conf": "{}"})
with create_session() as session:
run = session.query(DagRun).filter(DagRun.dag_id ==
test_dag_id).first()
assert run is not None
@@ -68,8 +68,12 @@ def test_trigger_dag_button(admin_client, req,
expected_run_id):
def test_duplicate_run_id(admin_client):
test_dag_id = "example_bash_operator"
run_id = "test_run"
- admin_client.post(f"dags/{test_dag_id}/trigger?run_id={run_id}",
follow_redirects=True)
- response =
admin_client.post(f"dags/{test_dag_id}/trigger?run_id={run_id}",
follow_redirects=True)
+ admin_client.post(
+ f"dags/{test_dag_id}/trigger?run_id={run_id}", data={"conf": "{}"},
follow_redirects=True
+ )
+ response = admin_client.post(
+ f"dags/{test_dag_id}/trigger?run_id={run_id}", data={"conf": "{}"},
follow_redirects=True
+ )
check_content_in_response(f"The run ID {run_id} already exists", response)
@@ -112,7 +116,9 @@ def test_trigger_dag_conf_not_dict(admin_client):
def test_trigger_dag_wrong_execution_date(admin_client):
test_dag_id = "example_bash_operator"
- response = admin_client.post(f"dags/{test_dag_id}/trigger",
data={"execution_date": "not_a_date"})
+ response = admin_client.post(
+ f"dags/{test_dag_id}/trigger", data={"conf": "{}", "execution_date":
"not_a_date"}
+ )
check_content_in_response("Invalid execution date", response)
with create_session() as session:
@@ -124,7 +130,9 @@ def
test_trigger_dag_execution_date_data_interval(admin_client):
test_dag_id = "example_bash_operator"
exec_date = timezone.utcnow()
- admin_client.post(f"dags/{test_dag_id}/trigger", data={"execution_date":
exec_date.isoformat()})
+ admin_client.post(
+ f"dags/{test_dag_id}/trigger", data={"conf": "{}", "execution_date":
exec_date.isoformat()}
+ )
with create_session() as session:
run = session.query(DagRun).filter(DagRun.dag_id ==
test_dag_id).first()
@@ -361,7 +369,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"
- admin_client.post(f"dags/{test_dag_id}/trigger?&run_id={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:
assert run is not None