Merge request filter failing when Approved-By used with various ordering

Summary

Merge request filter with Approved-By and various ordering is failing.

Steps to reproduce

  1. Go to merge requests list
  2. Filter by Approved-By
  3. Order by any of Milestone due date / Merged date / Closed date

Example Project

The error happens on gitlab-org/gitlab project

What is the current bug behavior?

Application gives 500

What is the expected correct behavior?

Relevant logs and/or screenshots

"exception.message": "PG::GroupingError: ERROR:  column \"milestones.due_date\" must appear in the GROUP BY clause or be used in an aggregate function\nLINE 1: ...uests\".\"id\" HAVING (COUNT(users.id) = 1) ORDER BY milestones...\n                                                             ^\n",

Output of checks

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

Edited by Imre Farkas