ashb commented on a change in pull request #15474:
URL: https://github.com/apache/airflow/pull/15474#discussion_r618468781



##########
File path: airflow/www/views.py
##########
@@ -2676,6 +2676,138 @@ def task_instances(self):
 
         return json.dumps(task_instances, cls=utils_json.AirflowJsonEncoder)
 
+    @expose('/object/tree_data')
+    @auth.has_access(
+        [
+            (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
+            (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
+        ]
+    )
+    @action_logging
+    def tree_data(self):
+        """Returns tree data"""
+        dag_id = request.args.get('dag_id')
+        dag = current_app.dag_bag.get_dag(dag_id)
+
+        if not dag:
+            flash(f'DAG "{dag_id}" seems to be missing from DagBag.', "error")
+            return redirect(url_for('Airflow.index'))

Review comment:
       Given this returns JSON, a 404 is probably more approriate
   
   ```suggestion
           if not dag:
               response = jsonify(
                   {
                       'error': f"can't find dag {dag_id}"
                   }
               )
               response.status_code = 404
               return response
   
   ```

##########
File path: airflow/www/templates/airflow/tree.html
##########
@@ -19,6 +19,12 @@
 
 {% extends "airflow/dag.html" %}
 {% block page_title %}{{ dag.dag_id }} - Tree - {{ appbuilder.app_name }}{% 
endblock %}
+{% from 'appbuilder/loading_dots.html' import loading_dots %}
+
+{% block head_meta %}
+  {{ super() }}
+  <meta name="dag_id" content="{{ dag.dag_id }}">

Review comment:
       Should this maybe go in the base dag.html template, and then get pulled 
out of graph.html?

##########
File path: airflow/www/views.py
##########
@@ -2676,6 +2676,138 @@ def task_instances(self):
 
         return json.dumps(task_instances, cls=utils_json.AirflowJsonEncoder)
 
+    @expose('/object/tree_data')
+    @auth.has_access(
+        [
+            (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
+            (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
+        ]
+    )
+    @action_logging
+    def tree_data(self):
+        """Returns tree data"""
+        dag_id = request.args.get('dag_id')
+        dag = current_app.dag_bag.get_dag(dag_id)
+
+        if not dag:
+            flash(f'DAG "{dag_id}" seems to be missing from DagBag.', "error")
+            return redirect(url_for('Airflow.index'))
+
+        root = request.args.get('root')
+        if root:
+            dag = dag.sub_dag(task_ids_or_regex=root, 
include_downstream=False, include_upstream=True)

Review comment:
       ```suggestion
               dag = dag.partial_subset(task_ids_or_regex=root, 
include_downstream=False, include_upstream=True)
   ```
   
   `sub_dag` is the old (confusing) name for this function.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to