Check placeholder empty rule before upateRules
What does this MR do and why?
The "Minimum required approvals" rule duplicates itself when set for the first time via POST request. After refreshing the page, only one rule displays correctly.
Root Cause
The Issue Flow
-
Initial State: Frontend creates a placeholder "Minimum required approvals" rule with
id: nullandruleType: 'any_approver' -
User Action: User sets the approval count for the first time
-
POST Request: Backend creates the rule and returns:
{ "id": 20, "name": "All Members", "rule_type": "any_approver", "approvals_required": 1, ... } -
Duplicate Check Fails: The existing logic in
updateRules()checks:const isRuleExist = rules.some(({ id }) => id === updatedRule.id); // Compares: null === 20 → false -
Result: The new rule is added to the array instead of replacing the placeholder, creating a duplicate
Why It Only Happens on POST (First Time)
-
POST: Creates a new rule with a new ID, placeholder has
id: null -
PUT: Updates existing rule with same ID, so the check
id === updatedRule.idworks correctly
Why Page Refresh Fixes It
- On refresh, the GET request fetches rules from the backend
- Backend only has one rule (the one created by POST)
- Frontend doesn't create the placeholder because a real rule exists
References
Screenshots or screen recordings
| Before | After |
|---|---|
|
|
|
|
How to set up and validate locally
- Go to a project. Make sure you're on EE license
- Open Settings / Merge requests and scroll down to Merge request approvals section
- Change default
0value of Minimum required approvals and verify that table row is not duplicated. Note that if you want to verify this more than once, you need to do it in a different project. Once you make a POST request, the backend will be returning theIDvalue.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #502876
Edited by Paulina Sedlak-Jakubowska




