ArgumentError: parent was not preloaded

Created by @reprazent.

This happens when searching on the explore/groups page or filtering child groups on a group page.

Introduced in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/14055

https://sentry.gitlap.com/gitlab/gitlabcom/issues/110278/

ArgumentError: parent was not preloaded
  app/models/concerns/group_descendant.rb:40:in `expand_hierarchy_for_child'
    raise ArgumentError.new('parent was not preloaded')
  app/models/concerns/group_descendant.rb:9:in `hierarchy'
    expand_hierarchy_for_child(self, self, hierarchy_top, preloaded)
  app/models/concerns/group_descendant.rb:27:in `block in build_hierarchy'
    descendant.hierarchy(hierarchy_top, descendants)
  app/models/concerns/group_descendant.rb:26:in `map'
    all_hierarchies = descendants.map do |descendant|
  app/models/concerns/group_descendant.rb:26:in `build_hierarchy'
    all_hierarchies = descendants.map do |descendant|
...
(124 additional frame(s) were not displayed)

ArgumentError: parent was not preloaded
Edited by Bob Van Landuyt