500 error when filtering by multiple labels

Summary

When filtering by multiple labels a user gets 500 error.

Steps to reproduce

  • Go to list of epics
  • Filter by multiple labels (eg. https://gitlab.com/groups/gitlab-org/-/epics?scope=all&utf8=%E2%9C%93&state=opened&label_name%5B%5D=Manage&label_name%5B%5D=Future )

What is the current bug behavior?

Error 500 returned

What is the expected correct behavior?

A filtered epics list is returned

Relevant logs and/or screenshots

https://sentry.gitlab.net/gitlab/gitlabcom/issues/511533/

Output of checks

This bug happens on GitLab.com

Possible fixes

The error is because of the following query:

SELECT COUNT(*) AS count_all, "epics"."id" AS epics_id FROM "epics" INNER JOIN "label_links" ON "label_links"."target_id" = "epics"."id" AND "label_links"."target_type" = 'Epic' INNER JOIN "labels" ON "labels"."id" = "label_links"."label_id" WHERE "epics"."group_id" = 6 AND "labels"."title" IN ('bug', 'plan') GROUP BY "epics"."id" HAVING COUNT(DISTINCT labels.title) = 2  ORDER BY end_date ASC NULLS LAST, id DESC, "epics"."id" DESC

This is because of these scopes: https://gitlab.com/gitlab-org/gitlab-ee/blob/master/ee/app/models/ee/epic.rb#L33

The ordering by id here is needless as it is added anyway.

Edited Nov 08, 2021 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading