AAP-52518: Fix Role User Assignment Cleanup on Inventory Deletion #16090
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
AAP-52518: Fix Role User Assignment Cleanup on Inventory Deletion
SUMMARY
Fixed role assignment orphaning issue where RoleUserAssignment records were not properly cleaned up when Controller inventories were deleted, causing 404 errors in the UI when users attempted to access role assignments for deleted inventories.
Root Cause: RBAC post-delete signals (
rbac_post_delete_remove_object_roles
) were not reliably cleaning up ObjectRole records during inventory deletion, particularly in async Celery task contexts. Since RoleUserAssignment records cascade delete via foreign key to ObjectRole, when ObjectRole cleanup failed, the assignments remained orphaned.Solution: Implemented defense-in-depth explicit role cleanup in both deletion paths:
delete_inventory()
Celery task insystem.py
Inventory.delete()
model method ininventory.py
This ensures role assignment cleanup works regardless of deletion context, signal reliability, or process isolation issues.
Related AAP-52518
ISSUE TYPE
COMPONENT NAME
ADDITIONAL INFORMATION
Files Modified:
awx/awx/main/models/inventory.py
- Added explicit ObjectRole cleanup indelete()
methodawx/awx/main/tasks/system.py
- Added defense-in-depth cleanup indelete_inventory()
taskawx/awx/main/tests/functional/dab_rbac/test_inventory_role_cleanup.py
- Comprehensive test suiteReproduction Steps (Before Fix):
Expected Behavior (After Fix):
Test Coverage:
Technical Implementation:
ObjectRole.objects.filter(content_type=ct, object_id=self.pk).delete()
beforesuper().delete()
inventory.delete()
in Celery taskVerification: