Commit 1ea93f10 authored by Felipe Artur's avatar Felipe Artur

Prevent grouping by ignored columns on database

Prevents grouping by issues.state column on database
parent 777410a8
...@@ -260,12 +260,14 @@ module Issuable ...@@ -260,12 +260,14 @@ module Issuable
highest_priority = highest_label_priority(params).to_sql highest_priority = highest_label_priority(params).to_sql
select_columns = [ # When using CTE make sure to select the same columns that are on the group_by clause.
"#{table_name}.*", # This prevents errors when ignored columns are present in the database.
"(#{highest_priority}) AS highest_priority" issuable_columns = with_cte ? issue_grouping_columns(use_cte: with_cte) : "#{table_name}.*"
] + extra_select_columns
select(select_columns.join(', ')) extra_select_columns = extra_select_columns.unshift("(#{highest_priority}) AS highest_priority")
select(issuable_columns)
.select(extra_select_columns)
.group(issue_grouping_columns(use_cte: with_cte)) .group(issue_grouping_columns(use_cte: with_cte))
.reorder(Gitlab::Database.nulls_last_order('highest_priority', direction)) .reorder(Gitlab::Database.nulls_last_order('highest_priority', direction))
end end
...@@ -301,7 +303,7 @@ module Issuable ...@@ -301,7 +303,7 @@ module Issuable
# Returns an array of arel columns # Returns an array of arel columns
def issue_grouping_columns(use_cte: false) def issue_grouping_columns(use_cte: false)
if use_cte if use_cte
[arel_table[:state]] + attribute_names.map { |attr| arel_table[attr.to_sym] } attribute_names.map { |attr| arel_table[attr.to_sym] }
else else
arel_table[:id] arel_table[:id]
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