Issuable listings: Filter by label=Any with custom sorting results in API error
Problem
At any MR\Issue listing pages (Code Review Analytics, Issues, MRs)
When filtering by label=Any
with custom sorting (e.g. review_time
or milestone_due_date
), the API responds with an error:
Sample request:
https://gitlab.com/api/v4/analytics/code_review?project_id=278964&label_name[]=Any&page=1
Other labels (including the label=None
option) work as expected.
Sentry report
https://sentry.gitlab.net/gitlab/gitlabcom/issues/1586422
Investigation
Any label filtering adds implicit grouping to the query, but doesn't add custom sorting attribute to grouping, so as a result Postgres blames that sorting attribute is not present in SELECT or GROUP part of query.
This error can happen not only at CRA but anywhere where custom sorting + label=Any is used. E.g. Issues listing or MRs listing
You can manually recreate the bug at https://gitlab.com/gitlab-org/gitlab/-/issues by using label=Any and sorting=Milestone Due Date
Fix Proposal
Here is how we handle it for other cases, so we'll need to adjust any_label
scope to be aware of custom sorting too.