Fix loading child items that are also related

What does this MR do and why?

Fixes #478524 (closed)

Fix loading child items that are also related

This fixes a bug when a work item is a child item and a related item at the same time.

Changelog: fixed

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After
bug fixed

How to set up and validate locally

Enable the following feature flags: work_item_epics, work_item_epics_rollout

  1. Create an epic
  2. Add a child epic
  3. Disable the validation by applying the following diff:
    diff --git a/app/models/concerns/linkable_item.rb b/app/models/concerns/linkable_item.rb
     index c91e3615ba75..412ca600fef5 100644
     --- a/app/models/concerns/linkable_item.rb
     +++ b/app/models/concerns/linkable_item.rb
     @@ -24,12 +24,12 @@ module LinkableItem
          private
      
          def check_existing_parent_link
     -      return unless source && target
     +      # return unless source && target
      
     -      existing_relation = WorkItems::ParentLink.for_parents([source, target]).for_children([source, target])
     -      return if existing_relation.none?
     +      # existing_relation = WorkItems::ParentLink.for_parents([source, target]).for_children([source, target])
     +      # return if existing_relation.none?
      
     -      errors.add(:source, format(_('is a parent or child of this %{item}'), item: self.class.issuable_name))
     +      # errors.add(:source, format(_('is a parent or child of this %{item}'), item: self.class.issuable_name))
          end
        end
      end
  4. Add the same child epic now as a linked epic
  5. Add 30 more child items so the child hierarchy widget needs to paginate
  6. Reload the page to see the pagination
  7. Click "Load more" -> before this change, an error appeared, with this fix the next child items get loaded
Edited by Nicolas Dular

Merge request reports

Loading