This is an automated email from the ASF dual-hosted git repository.

ephraimanierobi pushed a commit to branch v2-6-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 059b017a367cb1a2b6cbfce02a49d470ac6c27c8
Author: Hussein Awala <[email protected]>
AuthorDate: Sun Jun 25 10:06:34 2023 +0200

    Flash an error msg instead of failure in `rendered-templates` when map 
index is not found (#32011)
    
    ---------
    
    Signed-off-by: Hussein Awala <[email protected]>
    (cherry picked from commit 62a534dbc7fa8ddb4c249ade85c558b64d1630dd)
---
 airflow/www/views.py | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/airflow/www/views.py b/airflow/www/views.py
index 4907891d1b..8eaac3eec5 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -1340,6 +1340,9 @@ class Airflow(AirflowBaseView):
         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
@@ -1351,7 +1354,21 @@ class Airflow(AirflowBaseView):
             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)
@@ -1370,8 +1387,6 @@ class Airflow(AirflowBaseView):
         # 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:

Reply via email to