-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Fix: Clean up FAB permissions when deleting DAGs #54528
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
Fix: Clean up FAB permissions when deleting DAGs #54528
Conversation
4da40eb to
cda491d
Compare
|
Can you please add some unit tests? |
cda491d to
ccbc790
Compare
|
@potiuk, tests are added! |
ccbc790 to
a533d68
Compare
pierrejeambrun
left a comment
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.
Looking good, just a suggestion because I don't think this code should live in core.
cc: @vincbeck
a533d68 to
51bbff5
Compare
51bbff5 to
2e6c791
Compare
vincbeck
left a comment
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 am not against this change but here are some thoughts:
- Do we really want that? Example: As an admin, I give read permissions for the Dag
secretto X users. This Dag gets deleted and re-created, all permissions will be lost and I (the admin) needs to assign again permissions to my users. - Since this is very auth manager specific, and actually very Fab Auth manager specific. Should we not, instead, provide a CLI like
airflow fab-auth-manager permissions-cleanupwhich would delete all orphaned permissions. That way we do not need to wire the mechanism in Airflow with something likeif hasattr(...), and it would be up to the admin to run this command when they think it is needed
|
Thanks for the feedbak! I like the idea of using CLI command for it. 💪 @potiuk What are your thoughts on this? Any downsides I'm not seeing? |
The asseesment of @vincbeck and @pierrejeambrun are more than enough :) . I like it's off-loaded to Fab Auth Manager, this is FAB specific and having separate cleanup command looks like a good idea. |
Thanks for the feedback! Working on it. |
f94a416 to
e939a76
Compare
vincbeck
left a comment
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.
Few comments but overall I really like it better that way! Thanks for the changes!
providers/fab/src/airflow/providers/fab/auth_manager/dag_permissions.py
Outdated
Show resolved
Hide resolved
providers/fab/src/airflow/providers/fab/auth_manager/dag_permissions.py
Outdated
Show resolved
Hide resolved
pierrejeambrun
left a comment
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.
Looks good overall, a few suggestions.
providers/fab/src/airflow/providers/fab/auth_manager/cli_commands/permissions_command.py
Outdated
Show resolved
Hide resolved
providers/fab/src/airflow/providers/fab/auth_manager/cli_commands/permissions_command.py
Outdated
Show resolved
Hide resolved
providers/fab/src/airflow/providers/fab/auth_manager/cli_commands/permissions_command.py
Outdated
Show resolved
Hide resolved
providers/fab/tests/unit/fab/auth_manager/cli_commands/test_permissions_command.py
Show resolved
Hide resolved
providers/fab/tests/unit/fab/auth_manager/test_dag_permissions.py
Outdated
Show resolved
Hide resolved
|
Still working on the testing part, turned the PR into a draft. |
e939a76 to
0159fd3
Compare
This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations
- Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability
…al database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
ae03312 to
44bd723
Compare
|
Thanks for all the suggestion! This PR is ready for another review. |
vincbeck
left a comment
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.
Nice!
pierrejeambrun
left a comment
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.
Nice thanks
|
Thanks for the review! 🤩 |
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
* Fix: Clean up FAB permissions when deleting DAGs (apache#50905) This commit adds cleanup logic to the delete_dag function to: - Remove DAG-specific resources from ab_view_menu table - Clean up associated permissions and role associations * test: Add comprehensive tests for DAG permission cleanup Test Coverage: - Non-FAB auth manager scenarios (graceful skip) - FAB provider unavailable scenarios (import error handling) - Full cleanup process with mocked FAB models - Integration with delete_dag function - Edge cases (non-existent DAGs) * fix: clean up DAG permissions when deleting DAGs - : Simplified core logic using auth manager delegation - : Added cleanup_dag_permissions method - : New specialized module for FAB permission cleanup - Enhanced test coverage for multiple auth manager scenarios * feat(fab-auth-manager): replace automatic DAG permission cleanup with CLI command Replace automatic cleanup of DAG permissions during DAG deletion with a new CLI command approach as requested in code review. This gives operators explicit control over when and how DAG permissions are cleaned up. * feat(fab): Update DAG permissions cleanup to SQLAlchemy 2.0 and improve tests - Replace deprecated session.query() with session.scalars(select()) and session.execute(delete()) - Update permissions_command.py to use SQLAlchemy 2.0 syntax for better future compatibility - Rewrite test_permissions_command.py to use integration tests instead of fragile mocks * feat(fab): add missing test_dag_permissions.py Add unit tests for dag_permissions module to satisfy project structure requirements * refactor(fab): Consolidate DAG permissions code and modernize patterns - Replace hardcoded resource strings with constants in permissions_command.py - Use RESOURCE_DAG_PREFIX and RESOURCE_DETAILS_MAP for DAG Run - Remove deprecated Task Instance resource handling - Change to session handling with @provide_session decorator - Replace manual boolean parsing with airflow.utils.strings.to_boolean - Consolidate dag_permissions.py functionality into permissions_command.py - Consolidate test files for better maintainability * test: enhance FAB permissions tests with function verification and real database operations 1. Function call verification (TestPermissionsCommand) - Replace stdout-only testing with precise function call verification - Add mock assertions for cleanup_dag_permissions with exact parameters 2. Real database operations (TestDagPermissions): - Replace mock-heavy approach with actual database interactions - Use real Resource, Action, and Permission entities with constraint handling
Description
When a DAG is deleted, the corresponding Flask-AppBuilder (FAB) permissions remain in the database tables (
ab_view_menu,ab_permission_view,ab_permission_view_role). This causesHow this happend?
The
delete_dag()function indelete_dag.pysuccessfully removes DAG-related records from core Airflow tables but does not clean up the Flask-AppBuilder permission system.Solution
FAB Provider
dag_permissions.py: New module that handles FAB permission cleanup ( code referenced fromairflow/devel-common/src/tests_common/test_utils/db.py
Lines 358 to 393 in e00777a
fab_auth_manager.py: Addedcleanup_dag_permissions()methodTests: New tests for the permission cleanup logicCore Airflow (delete_dag.py)
auth_manager.cleanup_dag_permissions()Replace automatic DAG permission cleanup with CLI command
Changes:
delete_dag()functionairflow fab-auth-manager permissions-cleanupCLI commandCLI command supports
--dag-idoption--dry-runflag--yesflag--verboseflagExamples:
airflow fab-auth-manager permissions-cleanupairflow fab-auth-manager permissions-cleanup --dry-runairflow fab-auth-manager permissions-cleanup --dag-id my_dagairflow fab-auth-manager permissions-cleanup --yescloses: #50905
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.