@@ -474,3 +474,41 @@ def test_bulk_caching_memory_safe_mixed_operations(self, rando, team, inv_rd, or
474474
475475 # Should call full recomputation since we had net updates
476476 mock_obj_update .assert_called_once_with ()
477+
478+ def test_bulk_caching_with_removal (self , rando , inv_rd , inventory ):
479+ """Test bulk caching when object role gets deleted during removal"""
480+ # First give permission normally
481+ inv_rd .give_permission (rando , inventory )
482+
483+ with patch ('ansible_base.rbac.triggers.compute_object_role_permissions' ) as mock_obj_update :
484+
485+ with bulk_rbac_caching ():
486+ # Remove permission in bulk mode - this will delete the object role
487+ inv_rd .remove_permission (rando , inventory )
488+ mock_obj_update .assert_not_called ()
489+
490+ # Should not be called since object role was deleted (nothing to update)
491+ mock_obj_update .assert_not_called ()
492+
493+ def test_bulk_caching_team_only_updates_fix (self , rando , team , member_rd ):
494+ """Test that team-only updates properly call compute_object_role_permissions"""
495+ with (
496+ patch ('ansible_base.rbac.triggers.compute_team_member_roles' ) as mock_team_update ,
497+ patch ('ansible_base.rbac.triggers.compute_object_role_permissions' ) as mock_obj_update ,
498+ ):
499+
500+ with bulk_rbac_caching ():
501+ # This assignment affects team membership but doesn't create a new object role
502+ # that would be added to object_roles_to_update
503+ member_rd .give_permission (rando , team )
504+
505+ # Should not be called during bulk mode
506+ mock_team_update .assert_not_called ()
507+ mock_obj_update .assert_not_called ()
508+
509+ # CRITICAL: Both should be called when team updates happen
510+ # This ensures the permission cache reflects new team relationships
511+ mock_team_update .assert_called_once ()
512+ # This is the bug fix - compute_object_role_permissions should be called
513+ # even when only team updates occurred (no object_roles_to_update)
514+ mock_obj_update .assert_called_once_with ()
0 commit comments