From 82e5fc413e9f99049cd53377eb103ac4bc30091d Mon Sep 17 00:00:00 2001 From: "OMAR.A" <58332033+civilcoder55@users.noreply.github.com> Date: Thu, 22 Jun 2023 16:06:58 +0300 Subject: [PATCH] fix: Label Duplication in Bulk Actions (#7341) When looping the conversations in bulk action to assign them to new labels, the existing labels in other conversations were also getting duplicated across all conversations. This PR fixes the issue. > In the previous implementation, new_labels is appended to the existing labels using the << operator. This operator modifies the original array instead of creating a new one, causing unwanted side effects. More specifically, new_labels is a reference to the original argument array of the method. Co-authored-by: Sojan Co-authored-by: Peter Salib <74493166+Peteraymansalib@users.noreply.github.com> --- app/models/concerns/labelable.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/labelable.rb b/app/models/concerns/labelable.rb index 5a71fe84f..e710e97e9 100644 --- a/app/models/concerns/labelable.rb +++ b/app/models/concerns/labelable.rb @@ -10,7 +10,8 @@ module Labelable end def add_labels(new_labels = nil) - new_labels << labels - update!(label_list: new_labels) + new_labels = Array(new_labels) # Make sure new_labels is an array + combined_labels = labels + new_labels + update!(label_list: combined_labels) end end