You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/08/31 02:58:56 UTC

[GitHub] [airflow] jedcunningham commented on a change in pull request #17924: Display ImportErrors from all readable DAGs

jedcunningham commented on a change in pull request #17924:
URL: https://github.com/apache/airflow/pull/17924#discussion_r698945382



##########
File path: airflow/www/views.py
##########
@@ -678,18 +678,24 @@ def index(self):
                 for name, in dagtags
             ]
 
-            import_errors = session.query(errors.ImportError).order_by(errors.ImportError.id).all()
+            if (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG) in user_permissions:
+                import_errors = session.query(errors.ImportError).order_by(errors.ImportError.id).all()
 
-        if import_errors:
-            dag_filenames = {dag.fileloc for dag in dags}
-            all_dags_readable = (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG) in user_permissions
+            else:
+                # if the user doesn't have access to all DAGs, only display errors from visible DAGs
+                import_errors = (
+                    session.query(errors.ImportError)
+                    .join(DagModel, DagModel.fileloc == errors.ImportError.filename)
+                    .filter(DagModel.dag_id.in_(filter_dag_ids))
+                    .order_by(errors.ImportError.id)
+                ).all()
 
+        if import_errors:
             for import_error in import_errors:

Review comment:
       ```suggestion
           for import_error in import_errors:
   ```
   
   We can get rid of this `if` now.

##########
File path: airflow/www/views.py
##########
@@ -678,18 +678,24 @@ def index(self):
                 for name, in dagtags
             ]
 
-            import_errors = session.query(errors.ImportError).order_by(errors.ImportError.id).all()
+            if (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG) in user_permissions:
+                import_errors = session.query(errors.ImportError).order_by(errors.ImportError.id).all()
 
-        if import_errors:
-            dag_filenames = {dag.fileloc for dag in dags}
-            all_dags_readable = (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG) in user_permissions
+            else:
+                # if the user doesn't have access to all DAGs, only display errors from visible DAGs
+                import_errors = (
+                    session.query(errors.ImportError)
+                    .join(DagModel, DagModel.fileloc == errors.ImportError.filename)
+                    .filter(DagModel.dag_id.in_(filter_dag_ids))
+                    .order_by(errors.ImportError.id)
+                ).all()
 
+        if import_errors:
             for import_error in import_errors:
-                if all_dags_readable or import_error.filename in dag_filenames:
-                    flash(
-                        "Broken DAG: [{ie.filename}] {ie.stacktrace}".format(ie=import_error),
-                        "dag_import_error",
-                    )
+                flash(
+                    "Broken DAG: [{ie.filename}] {ie.stacktrace}".format(ie=import_error),
+                    "dag_import_error",
+                )

Review comment:
       ```suggestion
               flash(
                   "Broken DAG: [{ie.filename}] {ie.stacktrace}".format(ie=import_error),
                   "dag_import_error",
               )
   ```




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org