Unable to Reorder Rules from the Dashboard After Deleting a Rule

Problem statement

How can rules be reordered from within the Dashboard? The Dashboard throws an error when attempting to reorder the rules by dragging and dropping them. This error occurs after a rule is deleted, and an attempt is made to reorder the remaining rules.

Symptoms

  • When trying to reorder the Rules using the drag & drop option, the Dashboard throws an error.

Steps to reproduce

  1. Create three rules named Rule 1, Rule 2, and Rule 3 through the management dashboard.
  2. Delete Rule 2.
  3. Create Rule 4.
  4. Try and reorder Rule 1 and Rule 3.
  5. Observe the 500 error.

Troubleshooting

  • Please confirm that you have deleted the Rule before trying to re-order the remaining Rules.

Cause

There is a mismatch between Dashboard and the Management API where the API tries to PATCH /rules with this payload when you do the re-order:

[ 
 { "rule_id": "abc", "name": "Rule 1", "order": 1 },
 { "rule_id": "def", "name": "Rule 3", "order": 2 }, 
 { "rule_id": "ghi", "name": "Rule 4", "order": 3 }
]

However, due to Rule 2 being deleted prior to the reorder, the data stored by the API is:

[ 
{ "rule_id": "abc", "name": "Rule 1", "order": 1 }, 
{ "rule_id": "def", "name": "Rule 3", "order": 3 }, 
{ "rule_id": "ghi", "name": "Rule 4", "order": 4 } 
]

This inconsistency in how the orders are calculated causes an exception in the back-end.

Solution

To resolve this issue, manually reorder the rules by using the PATCH /rules Management API endpoint.

To change from
Rule 1Rule 3Rule 4
to
Rule 1Rule 4Rule 3 ,
make the following PATCH /rules request:

{
  { "rule_id": "abc", "name": "Rule 1", "order": 1 },
  { "rule_id": "def", "name": "Rule 3", "order": 4 },
  { "rule_id": "ghi", "name": "Rule 4", "order": 3 }
}