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

Stop adding values to rendered templates UI when there is no dagrun #33516

Merged
merged 1 commit into from
Aug 19, 2023
Merged
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
20 changes: 14 additions & 6 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,8 @@ def rendered_templates(self, session):
dag_run = dag.get_dagrun(execution_date=dttm, session=session)
raw_task = dag.get_task(task_id).prepare_for_execution()

no_dagrun = False

title = "Rendered Template"
html_dict = {}

Expand All @@ -1457,6 +1459,7 @@ def rendered_templates(self, session):
# database) for presentation only.
ti = TaskInstance(raw_task, map_index=map_index)
ti.dag_run = DagRun(dag_id=dag_id, execution_date=dttm)
no_dagrun = True
else:
ti = dag_run.get_task_instance(task_id=task_id, map_index=map_index, session=session)
if ti:
Expand Down Expand Up @@ -1502,28 +1505,33 @@ def rendered_templates(self, session):
content = getattr(task, template_field)
renderer = task.template_fields_renderers.get(template_field, template_field)
if renderer in renderers:
html_dict[template_field] = renderers[renderer](content)
html_dict[template_field] = renderers[renderer](content) if not no_dagrun else ""
else:
html_dict[template_field] = Markup("<pre><code>{}</pre></code>").format(pformat(content))
html_dict[template_field] = Markup("<pre><code>{}</pre></code>").format(
pformat(content) if not no_dagrun else ""
)

if isinstance(content, dict):
if template_field == "op_kwargs":
for key, value in content.items():
renderer = task.template_fields_renderers.get(key, key)
if renderer in renderers:
html_dict[".".join([template_field, key])] = renderers[renderer](value)
html_dict[".".join([template_field, key])] = (
renderers[renderer](value) if not no_dagrun else ""
)
else:
html_dict[".".join([template_field, key])] = Markup(
"<pre><code>{}</pre></code>"
).format(pformat(value))
).format(pformat(value) if not no_dagrun else "")
else:
for dict_keys in get_key_paths(content):
template_path = ".".join((template_field, dict_keys))
renderer = task.template_fields_renderers.get(template_path, template_path)
if renderer in renderers:
content_value = get_value_from_path(dict_keys, content)
html_dict[template_path] = renderers[renderer](content_value)

html_dict[template_path] = (
renderers[renderer](content_value) if not no_dagrun else ""
)
return self.render_template(
"airflow/ti_code.html",
show_trigger_form_if_no_params=conf.getboolean("webserver", "show_trigger_form_if_no_params"),
Expand Down