-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Skip DAG perm sync during parsing if possible #15464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
For DAGs without `access_control` that already have their PermissionView records, we can skip syncing their permissions during parsing. This cuts down on database queries and is faster (~2 seconds, mostly import time).
f1a8d99 to
7a67725
Compare
airflow/security/permissions.py
Outdated
| DAG_PERMS = {ACTION_CAN_READ, ACTION_CAN_EDIT} | ||
|
|
||
|
|
||
| def prefixed_dag_id(dag_id): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename this to permission_for_dag or something better? WDYT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went back and forth on renaming it since it is being moved from www/security, but I'm also happy with a more descriptive name. Related, should we follow up later with deprecating the method in www/security?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup agreed on deprecated method in www/security
airflow/models/dagbag.py
Outdated
| from flask_appbuilder.security.sqla import models as sqla_models | ||
|
|
||
| from airflow.security.permissions import DAG_PERMS, prefixed_dag_id | ||
|
|
||
| def needs_perm_views(dag_id: str) -> bool: | ||
| view_menu_name = prefixed_dag_id(dag_id) | ||
| for permission_name in DAG_PERMS: | ||
| if not ( | ||
| session.query(sqla_models.PermissionView) | ||
| .join(sqla_models.Permission) | ||
| .join(sqla_models.ViewMenu) | ||
| .filter(sqla_models.Permission.name == permission_name) | ||
| .filter(sqla_models.ViewMenu.name == view_menu_name) | ||
| .one_or_none() | ||
| ): | ||
| return True | ||
| return False | ||
|
|
||
| if dag.access_control or needs_perm_views(dag.dag_id): | ||
| self.log.debug("Syncing DAG permissions: %s to the DB", dag.dag_id) | ||
| from airflow.www.security import ApplessAirflowSecurityManager | ||
|
|
||
| security_manager = ApplessAirflowSecurityManager(session=session) | ||
| security_manager.sync_perm_for_dag(dag.dag_id, dag.access_control) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we separate this code block to a separate internal method too -- will be easier and test just that block in isolation too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By this I mean the entire block from L548:L571
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored the tests in a separate commit. I can go both ways here.
Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com>
For DAGs without `access_control` that already have their PermissionView records, we can skip syncing their permissions during parsing. This cuts down on database queries and is faster (~2 seconds, mostly import time). (cherry picked from commit 3bfe0e0)
For DAGs without
access_controlthat already have their PermissionViewrecords, we can skip syncing their permissions during parsing. This cuts
down on database queries and is faster (~2 seconds, mostly import time).