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

  1. Initial State: Frontend creates a placeholder "Minimum required approvals" rule with id: null and ruleType: 'any_approver'

  2. User Action: User sets the approval count for the first time

  3. POST Request: Backend creates the rule and returns:

    {
      "id": 20,
      "name": "All Members",
      "rule_type": "any_approver",
      "approvals_required": 1,
      ...
    }
  4. Duplicate Check Fails: The existing logic in updateRules() checks:

    const isRuleExist = rules.some(({ id }) => id === updatedRule.id);
    // Compares: null === 20 → false
  5. 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.id works 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
Screenshot_2025-11-04_at_19.13.56 Screenshot_2025-11-04_at_18.57.00
Screenshot_2025-11-04_at_19.14.23 Screenshot_2025-11-04_at_19.14.34 Screenshot_2025-11-04_at_18.57.56

How to set up and validate locally

  1. Go to a project. Make sure you're on EE license
  2. Open Settings / Merge requests and scroll down to Merge request approvals section
  3. Change default 0 value 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 the ID value.

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

Merge request reports

Loading