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 05:51:15 UTC

[GitHub] [airflow] uranusjr commented on pull request #17924: Display ImportErrors from all readable DAGs

uranusjr commented on pull request #17924:
URL: https://github.com/apache/airflow/pull/17924#issuecomment-908920361


   ```python
   if (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG) in user_permissions:
   	import_errors = session.query(errors.ImportError).order_by(errors.ImportError.id).all()
   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()
   ```
   
   Since `import_errors` is only used for iteration in the subsequent `for` block, this can be made cleaner (and likely more performant) as:
   
   ```python
   import_errors = session.query(errors.ImportError).order_by(errors.ImportError.id)
   if (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG) not in user_permissions:
       import_errors = (
   		import_errors
   		.join(DagModel, DagModel.fileloc == errors.ImportError.filename)
   		.filter(DagModel.dag_id.in_(filter_dag_ids))
   	)
   ```
   
   A SQLAlchemy Query instnace is lazily iterable, so this avoids loading the ImportError objects into memory all at once, but one by one instead.


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