Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Gracefully handle unknown input for filter and group by in Cost Query

Klaus Zandersbb6a904b9fd1
diff --git a/modules/reporting/app/models/cost_query.rb b/modules/reporting/app/models/cost_query.rb
index 5317137f98b..22e4f885581 100644
--- a/modules/reporting/app/models/cost_query.rb
+++ b/modules/reporting/app/models/cost_query.rb
@@ -158,7 +158,12 @@ class CostQuery < ApplicationRecord
end
def add_chain(type, name, options)
- chain type.const_get(name.to_s.camelcase), options
+ begin
+ chain type.const_get(name.to_s.camelcase), options
+ rescue NameError
+ # if something ends up in the column chain that does not exist, ignore it
+ end
+
@transformer = nil
@table = nil
@depths = nil
diff --git a/modules/reporting/spec/models/cost_query/filter_spec.rb b/modules/reporting/spec/models/cost_query/filter_spec.rb
index 89bf1b83300..b7e1facbf89 100644
--- a/modules/reporting/spec/models/cost_query/filter_spec.rb
+++ b/modules/reporting/spec/models/cost_query/filter_spec.rb
@@ -60,6 +60,10 @@ RSpec.describe CostQuery, :reporting_query_helper do
end
end
+ it "does not fail when grouping by a non-existent column" do
+ expect { query.filter(:non_existent_column, value: "something").result }.not_to raise_error
+ end
+
it "sets activity_id to -1 for cost entries" do
query.result.each do |result|
expect(result["activity_id"].to_i).to eq(-1) if result["type"] != "TimeEntry"
diff --git a/modules/reporting/spec/models/cost_query/group_by_spec.rb b/modules/reporting/spec/models/cost_query/group_by_spec.rb
index b7803c7e55e..0a298f68b7f 100644
--- a/modules/reporting/spec/models/cost_query/group_by_spec.rb
+++ b/modules/reporting/spec/models/cost_query/group_by_spec.rb
@@ -74,6 +74,10 @@ RSpec.describe CostQuery, :reporting_query_helper do
minimal_query
describe CostQuery::GroupBy do
+ it "does not fail when grouping by a non-existent column" do
+ expect { query.group_by(:non_existent_column).result }.not_to raise_error
+ end
+
it "computes group_by on projects" do
query.group_by :project_id
expect(query.result.size).to eq(2)