Skip to content

Milestone issues are not sorted after upgrading to v18.3

Summary

When testing on 18.0.1, the project Milestone page shows issues in order of descending issue ID. On GitLab.com (also v18.3) the project Milestone page shows issues without any order.

Steps to reproduce

  1. Create a project level milestone
  2. Create 5 issues in the project and assign them to the milestone
  3. Navigate to the milestone page
  4. Observe the mess on the milestone page

Example Project

Any project milestone page, example: https://gitlab.com/gitlab-org/security-products/rezilion/rezilion/-/milestones/48#tab-issues

What is the current bug behavior?

Issues have no order on project milestone page.

What is the expected correct behavior?

Issues sorted in descending order on project milestone page.

Relevant logs and/or screenshots

image

Output of checks

This bug happens on GitLab.com

Results of GitLab environment info

Expand for output related to GitLab environment info

 (For installations with omnibus-gitlab package run and paste the output of: \`sudo gitlab-rake gitlab:env:info\`)  (For installations from source run and paste the output of: \`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production\`)  

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:check SANITIZE=true`)

(For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true`)

(we will only investigate if the tests are passing)

Possible fixes

@ffarukh did some investigation

The sorting was previously done by label_priority which apparently has never worked.
Right now, we'd expect the sort to respect id: desc as per this line - https://gitlab.com/gitlab-org/gitlab/blob/master/app/finders/issuable_finder.rb?ref_type=heads#L408 but this doesn't work either.
 
In her debugging, it seems the sort by ID desc is overwritten by this code block - https://gitlab.com/gitlab-org/gitlab/blob/master/app/models/concerns/milestoneish.rb?ref_type=heads#L75-77 which returns a random sorted list

WorkItem.where(id: WorkItem.select(:id).from(work_item_ids))    .preload_associated_models    .preload(namespace: :route)

 
Not sure why we have 2 queries. We should open an MR and change

work_item_ids = ::WorkItems::WorkItemsFinder.new(user, work_items_finder_params)    .execute.preload_associated_models    .where(milestone_id: milestoneish_id)    .limit(DISPLAY_ISSUES_LIMIT)    WorkItem.where(id: WorkItem.select(:id).from(work_item_ids))    .preload_associated_models    .preload(namespace: :route)

 
TO:

WorkItems::WorkItemsFinder.new(user, work_items_finder_params)  .execute  .preload_associated_models  .where(milestone_id: milestoneish_id)  .limit(DISPLAY_ISSUES_LIMIT)  .preload(namespace: :route)

 
Works well in her GDK, but not sure if there are any performance issues that may be caused by this.

Patch release information for backports

If the bug fix needs to be backported in a patch release to a version under the maintenance policy, please follow the steps on the patch release runbook for GitLab engineers.

Refer to the internal "Release Information" dashboard for information about the next patch release, including the targeted versions, expected release date, and current status.

High-severity bug remediation

To remediate high-severity issues requiring an internal release for single-tenant SaaS instances, refer to the internal release process for engineers.

Edited by 🤖 GitLab Bot 🤖