fix: Move call to `AiRelatedSettingsChangedEvent`
-
Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA. As a benefit of being a GitLab Community Contributor, you receive complimentary access to GitLab Duo.
What does this MR do and why?
This MR fixes a potential issue with the AiRelatedSettingsChangedEvent being published prematurely. Previously, the event was being emitted from NamespaceSettings::AssignAttributesService which only assigns attributes but doesn't persist them. This could lead to events being published for changes that weren't actually saved to the database.
Changes made:
- Moved event publishing from
NamespaceSettings::AssignAttributesServicetoGroups::UpdateService'safter_updatecallback - Updated the logic to check for actual persisted changes using
saved_change_to_attribute? - Added comprehensive specs to verify event publishing behavior
This ensures that events are only published when:
- The update is successful
- There are actual persisted changes to AI-related settings
- The namespace settings exist
References
- Issue #444224 (closed): Move AiRelatedSettingsChangedEvent to after_update
How to set up and validate locally
-
Start GDK:
gdk start -
In rails console, set up a test group:
# Create organization organization = Organizations::Organization.create!( name: 'Test Organization', path: 'test-organization' ) # Create group user = User.first group = Group.create!( name: 'test-group', path: 'test-group', visibility_level: Gitlab::VisibilityLevel::PRIVATE, organization: organization ) group.add_owner(user) -
Test the AI settings change:
# Update settings service = Groups::UpdateService.new(group, user, { experiment_features_enabled: true }) result = service.execute # Verify change group.reload.namespace_settings.experiment_features_enabled # Should be true -
Monitor logs to verify event publishing:
gdk tail | grep AiRelatedSettingsChangedEvent
MR acceptance checklist
-
The change is isolated to the event publishing logic -
Added comprehensive specs for success and failure cases -
No changes to database schema -
No changes to API endpoints -
Event is only published after successful updates
Edited by Yashika Jotwani