Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DAG Docs to Trigger UI #13365

Merged
merged 4 commits into from
Jan 7, 2021
Merged
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/www/templates/airflow/trigger.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
#}

{% extends base_template %}
{% from 'appbuilder/dag_docs.html' import dag_docs %}

{% block content %}
{{ super() }}
<h2>Trigger DAG: {{ dag_id }}</h2>
{{ dag_docs(doc_md) }}
<form method="POST">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<input type="hidden" name="dag_id" value="{{ dag_id }}">
Expand Down
7 changes: 5 additions & 2 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,16 +1409,19 @@ def trigger(self, session=None):
if request.method == 'GET':
# Populate conf textarea with conf requests parameter, or dag.params
default_conf = ''

dag = current_app.dag_bag.get_dag(dag_id)
doc_md = wwwutils.wrapped_markdown(getattr(dag, 'doc_md', None))

if request_conf:
default_conf = request_conf
else:
try:
dag = current_app.dag_bag.get_dag(dag_id)
default_conf = json.dumps(dag.params, indent=4)
except TypeError:
flash("Could not pre-populate conf field due to non-JSON-serializable data-types")
return self.render_template(
'airflow/trigger.html', dag_id=dag_id, origin=origin, conf=default_conf
'airflow/trigger.html', dag_id=dag_id, origin=origin, conf=default_conf, doc_md=doc_md
)

dag_orm = session.query(models.DagModel).filter(models.DagModel.dag_id == dag_id).first()
Expand Down
3 changes: 2 additions & 1 deletion tests/www/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2783,12 +2783,13 @@ def test_trigger_dag_params_conf(self, request_conf, expected_conf):
2. Conf is passed as a URL parameter -> passed conf json is in textarea
"""
test_dag_id = "example_bash_operator"
doc_md = "Example Bash Operator"

if not request_conf:
resp = self.client.get(f'trigger?dag_id={test_dag_id}')
else:
test_request_conf = json.dumps(request_conf, indent=4)
resp = self.client.get(f'trigger?dag_id={test_dag_id}&conf={test_request_conf}')
resp = self.client.get(f'trigger?dag_id={test_dag_id}&conf={test_request_conf}&doc_md={doc_md}')

expected_dag_conf = json.dumps(expected_conf, indent=4).replace("\"", "&#34;")

Expand Down