diff --git a/airflow/www/views.py b/airflow/www/views.py index f50df518fe95a..32a0f0c19e1f4 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -1408,6 +1408,9 @@ 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() + title = "Rendered Template" + html_dict = {} + ti: TaskInstance if dag_run is None: # No DAG run matching given logical date. This usually means this @@ -1419,7 +1422,21 @@ def rendered_templates(self, session): ti.dag_run = DagRun(dag_id=dag_id, execution_date=dttm) else: ti = dag_run.get_task_instance(task_id=task_id, map_index=map_index, session=session) - ti.refresh_from_task(raw_task) + if ti: + ti.refresh_from_task(raw_task) + else: + flash(f"there is no task instance with the provided map_index {map_index}", "error") + return self.render_template( + "airflow/ti_code.html", + html_dict=html_dict, + dag=dag, + task_id=task_id, + execution_date=execution_date, + map_index=map_index, + form=form, + root=root, + title=title, + ) try: ti.get_rendered_template_fields(session=session) @@ -1439,8 +1456,6 @@ def rendered_templates(self, session): # but we'll display some quasi-meaingful field names. task = ti.task.unmap(None) - title = "Rendered Template" - html_dict = {} renderers = wwwutils.get_attr_renderer() for template_field in task.template_fields: