Skip to content

Conversation

@HsiuChuanHsu
Copy link
Contributor

@HsiuChuanHsu HsiuChuanHsu commented Aug 14, 2025

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 causes

  1. Orphaned permissions: Deleted DAGs continue to appear in the permission management UI
  2. User confusion: Users see permissions for non-existent DAGs

How this happend?

The delete_dag() function in delete_dag.py successfully 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 from
      def clear_dag_specific_permissions():
      if "FabAuthManager" not in conf.get("core", "auth_manager"):
      return
      try:
      from airflow.providers.fab.auth_manager.models import Permission, Resource, assoc_permission_role
      except ImportError:
      # Handle Pre-airflow 2.9 case where FAB was part of the core airflow
      from airflow.providers.fab.auth.managers.fab.models import (
      Permission,
      Resource,
      assoc_permission_role,
      )
      except RuntimeError as e:
      # Handle case where FAB provider is not even usable
      if "needs Apache Airflow 2.9.0" in str(e):
      from airflow.providers.fab.auth.managers.fab.models import (
      Permission,
      Resource,
      assoc_permission_role,
      )
      else:
      raise
      with create_session() as session:
      dag_resources = session.query(Resource).filter(Resource.name.like(f"{RESOURCE_DAG_PREFIX}%")).all()
      dag_resource_ids = [d.id for d in dag_resources]
      dag_permissions = session.query(Permission).filter(Permission.resource_id.in_(dag_resource_ids)).all()
      dag_permission_ids = [d.id for d in dag_permissions]
      session.query(assoc_permission_role).filter(
      assoc_permission_role.c.permission_view_id.in_(dag_permission_ids)
      ).delete(synchronize_session=False)
      session.query(Permission).filter(Permission.resource_id.in_(dag_resource_ids)).delete(
      synchronize_session=False
      )
      session.query(Resource).filter(Resource.id.in_(dag_resource_ids)).delete(synchronize_session=False)
      )
    • fab_auth_manager.py: Added cleanup_dag_permissions() method
    • Tests: New tests for the permission cleanup logic
  • Core Airflow (delete_dag.py)

    • Now calls auth_manager.cleanup_dag_permissions()
    • Added error handling so DAG deletion doesn't fail if permission cleanup fails

Replace automatic DAG permission cleanup with CLI command

  • Changes:

    • Remove automatic permission cleanup from delete_dag() function
    • Add new airflow fab-auth-manager permissions-cleanup CLI command
    • Support both global orphaned permission cleanup and specific DAG cleanup
  • CLI command supports

    • Cleaning up orphaned permissions for deleted DAGs (default behavior)
    • Cleaning up permissions for specific DAG with --dag-id option
    • Dry-run mode with --dry-run flag
    • Skip confirmation with --yes flag
    • Verbose output with --verbose flag
  • Examples:

    • airflow fab-auth-manager permissions-cleanup
    • airflow fab-auth-manager permissions-cleanup --dry-run
    • airflow fab-auth-manager permissions-cleanup --dag-id my_dag
    • airflow fab-auth-manager permissions-cleanup --yes

closes: #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.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@boring-cyborg boring-cyborg bot added the area:API Airflow's REST/HTTP API label Aug 14, 2025
@HsiuChuanHsu HsiuChuanHsu force-pushed the bug/remove-deleted-dag-correctly branch from 4da40eb to cda491d Compare August 14, 2025 23:01
@potiuk
Copy link
Member

potiuk commented Aug 18, 2025

Can you please add some unit tests?

@HsiuChuanHsu HsiuChuanHsu force-pushed the bug/remove-deleted-dag-correctly branch from cda491d to ccbc790 Compare August 19, 2025 23:20
@HsiuChuanHsu
Copy link
Contributor Author

@potiuk, tests are added!

@HsiuChuanHsu HsiuChuanHsu force-pushed the bug/remove-deleted-dag-correctly branch from ccbc790 to a533d68 Compare August 20, 2025 13:15
Copy link
Member

@pierrejeambrun pierrejeambrun left a 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

@HsiuChuanHsu HsiuChuanHsu force-pushed the bug/remove-deleted-dag-correctly branch from a533d68 to 51bbff5 Compare August 21, 2025 23:07
@HsiuChuanHsu HsiuChuanHsu requested a review from vincbeck as a code owner August 21, 2025 23:07
@HsiuChuanHsu HsiuChuanHsu force-pushed the bug/remove-deleted-dag-correctly branch from 51bbff5 to 2e6c791 Compare August 21, 2025 23:08
Copy link
Contributor

@vincbeck vincbeck left a 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 secret to 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-cleanup which would delete all orphaned permissions. That way we do not need to wire the mechanism in Airflow with something like if hasattr(...), and it would be up to the admin to run this command when they think it is needed

@HsiuChuanHsu
Copy link
Contributor Author

Thanks for the feedbak! I like the idea of using CLI command for it. 💪
It gives admins control over when to clean up orphaned permissions, which I believe is more robust. Plus, it keeps the main code cleaner and less tied to a specific auth manager.

@potiuk What are your thoughts on this? Any downsides I'm not seeing?

@potiuk
Copy link
Member

potiuk commented Aug 27, 2025

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

@HsiuChuanHsu
Copy link
Contributor Author

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.

@HsiuChuanHsu HsiuChuanHsu force-pushed the bug/remove-deleted-dag-correctly branch 4 times, most recently from f94a416 to e939a76 Compare September 1, 2025 12:39
Copy link
Contributor

@vincbeck vincbeck left a 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!

Copy link
Member

@pierrejeambrun pierrejeambrun left a 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.

@HsiuChuanHsu HsiuChuanHsu marked this pull request as draft September 3, 2025 23:14
@HsiuChuanHsu
Copy link
Contributor Author

Still working on the testing part, turned the PR into a draft.

@HsiuChuanHsu HsiuChuanHsu force-pushed the bug/remove-deleted-dag-correctly branch from e939a76 to 0159fd3 Compare September 3, 2025 23:24
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
@HsiuChuanHsu HsiuChuanHsu force-pushed the bug/remove-deleted-dag-correctly branch from ae03312 to 44bd723 Compare September 4, 2025 23:46
@HsiuChuanHsu HsiuChuanHsu marked this pull request as ready for review September 5, 2025 01:34
@HsiuChuanHsu
Copy link
Contributor Author

Thanks for all the suggestion! This PR is ready for another review.

Copy link
Contributor

@vincbeck vincbeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thanks

@vincbeck vincbeck merged commit 4d1d318 into apache:main Sep 5, 2025
138 checks passed
@HsiuChuanHsu
Copy link
Contributor Author

Thanks for the review! 🤩

mangal-vairalkar pushed a commit to mangal-vairalkar/airflow that referenced this pull request Sep 7, 2025
* 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
RoyLee1224 pushed a commit to RoyLee1224/airflow that referenced this pull request Sep 8, 2025
* 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
@HsiuChuanHsu HsiuChuanHsu deleted the bug/remove-deleted-dag-correctly branch September 9, 2025 22:19
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Sep 30, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 1, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 2, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 3, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 4, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 5, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 5, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 7, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 8, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 9, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 10, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 11, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 12, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 14, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 15, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 17, 2025
* 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
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 19, 2025
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deleted DAGs not removed from ab_view_menu table and show up in permissions (Airflow 2.7.3)

5 participants