Skip to content

Error 500 when sorting issues by Milestone due date and filtering by more than one Label

Example: https://gitlab.com/gitlab-org/gitlab-ce/issues?scope=all&sort=milestone_due_asc&state=opened&utf8=%E2%9C%93&label_name%5B%5D=Merge+Requests&label_name%5B%5D=Release

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

PG::GroupingError: ERROR:  column "milestones.due_date" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...HAVING count(distinct labels.title) = 2  ORDER BY milestones...
                                                             ^

  app/views/projects/issues/_issues.html.haml:2:in `_app_views_projects_issues__issues_html_haml__64912156108089974_48034320'
    = render @issues
  app/views/projects/issues/index.html.haml:25:in `_app_views_projects_issues_index_html_haml___1265384176385586197_70316925100340'
    = render "issues"
  app/controllers/projects/issues_controller.rb:38:in `index'
    respond_to do |format|
  lib/gitlab/metrics/rack_middleware.rb:17:in `block in call'
    retval = trans.run { @app.call(env) }
  lib/gitlab/metrics/transaction.rb:45:in `run'
    yield
...
(166 additional frame(s) were not displayed)

ActiveRecord::StatementInvalid: PG::GroupingError: ERROR:  column "milestones.due_date" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...HAVING count(distinct labels.title) = 2  ORDER BY milestones...
                                                             ^
: SELECT  "issues".* FROM "issues" INNER JOIN "label_links" ON "label_links"."target_id" = "issues"."id" AND "label_links"."target_type" = $1 INNER JOIN "labels" ON "labels"."id" = "label_links"."label_id" INNER JOIN "milestones" ON "milestones"."id" = "issues"."milestone_id" WHERE "issues"."deleted_at" IS NULL AND "issues"."confidential" = $2 AND ("issues"."state" IN ('opened','reopened')) AND "issues"."project_id" = 13083 AND "labels"."title" IN ('Merge Requests', 'Release') AND "labels"."project_id" = 13083 GROUP BY issues.id HAVING count(distinct labels.title) = 2  ORDER BY milestones.due_date ASC, milestones.id ASC LIMIT 20 OFFSET 0
  app/views/projects/issues/_issues.html.haml:2:in `_app_views_projects_issues__issues_html_haml__64912156108089974_48034320'
    = render @issues
  app/views/projects/issues/index.html.haml:25:in `_app_views_projects_issues_index_html_haml___1265384176385586197_70316925100340'
    = render "issues"
  app/controllers/projects/issues_controller.rb:38:in `index'
    respond_to do |format|
  lib/gitlab/metrics/rack_middleware.rb:17:in `block in call'
    retval = trans.run { @app.call(env) }
  lib/gitlab/metrics/transaction.rb:45:in `run'
    yield
...
(166 additional frame(s) were not displayed)

ActionView::Template::Error: PG::GroupingError: ERROR:  column "milestones.due_date" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...HAVING count(distinct labels.title) = 2  ORDER BY milestones...
                                                             ^
: SELECT  "issues".* FROM "issues" INNER JOIN "label_links" ON "label_links"."target_id" = "issues"."id" AND "label_links"."target_type" = $1 INNER JOIN "labels" ON "labels"."id" = "label_links"."label_id" INNER JOIN "milestones" ON "milestones"."id" = "issues"."milestone_id" WHERE "issues"."deleted_at" IS NULL AND "issues"."confidential" = $2 AND ("issues"."state" IN ('opened','reopened')) AND "issues"."project_id" = 13083 AND "labels"."title" IN ('Merge Requests', 'Release') AND "labels"."project_id" = 13083 GROUP BY issues.id HAVING count(distinct labels.title) = 2  ORDER BY milestones.due_date ASC, milestones.id ASC LIMIT 20 OFFSET 0
  app/views/projects/issues/_issues.html.haml:2:in `_app_views_projects_issues__issues_html_haml__64912156108089974_48034320'
    = render @issues
  app/views/projects/issues/index.html.haml:25:in `_app_views_projects_issues_index_html_haml___1265384176385586197_70316925100340'
    = render "issues"
  app/controllers/projects/issues_controller.rb:38:in `index'
    respond_to do |format|
  lib/gitlab/metrics/rack_middleware.rb:17:in `block in call'
    retval = trans.run { @app.call(env) }
  lib/gitlab/metrics/transaction.rb:45:in `run'
    yield
...
(166 additional frame(s) were not displayed)