Commit 296d9fa1 authored by Robert Speicher's avatar Robert Speicher

Merge branch '280535-fix-mr-analytics-query-error' into 'master'

Fix PG::GroupingError with label filters on MR analytics page

See merge request gitlab-org/gitlab!51060
parents 9b4fe6d0 45547ec4
...@@ -352,12 +352,15 @@ module Issuable ...@@ -352,12 +352,15 @@ module Issuable
# #
# Returns an array of arel columns # Returns an array of arel columns
def grouping_columns(sort) def grouping_columns(sort)
sort = sort.to_s
grouping_columns = [arel_table[:id]] grouping_columns = [arel_table[:id]]
if %w(milestone_due_desc milestone_due_asc milestone).include?(sort) if %w(milestone_due_desc milestone_due_asc milestone).include?(sort)
milestone_table = Milestone.arel_table milestone_table = Milestone.arel_table
grouping_columns << milestone_table[:id] grouping_columns << milestone_table[:id]
grouping_columns << milestone_table[:due_date] grouping_columns << milestone_table[:due_date]
elsif %w(merged_at_desc merged_at_asc).include?(sort)
grouping_columns << MergeRequest::Metrics.arel_table[:merged_at]
end end
grouping_columns grouping_columns
......
---
title: Fix merge request analytics page filtering when multiple labels are given
merge_request: 51060
author:
type: fixed
...@@ -231,6 +231,16 @@ RSpec.describe Resolvers::MergeRequestsResolver do ...@@ -231,6 +231,16 @@ RSpec.describe Resolvers::MergeRequestsResolver do
it 'sorts merge requests descending' do it 'sorts merge requests descending' do
expect(resolve_mr(project, sort: :merged_at_desc)).to eq [merge_request_3, merge_request_1, merge_request_with_milestone, merge_request_6, merge_request_5, merge_request_4, merge_request_2] expect(resolve_mr(project, sort: :merged_at_desc)).to eq [merge_request_3, merge_request_1, merge_request_with_milestone, merge_request_6, merge_request_5, merge_request_4, merge_request_2]
end end
context 'when label filter is given and the optimized_issuable_label_filter feature flag is off' do
before do
stub_feature_flags(optimized_issuable_label_filter: false)
end
it 'does not raise PG::GroupingError' do
expect { resolve_mr(project, sort: :merged_at_desc, labels: %w[a b]) }.not_to raise_error
end
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment