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

[#66093] Simplify detection of missing values

Tobias Dillmanna316deda7979
diff --git a/app/models/calculated_values/error_handler.rb b/app/models/calculated_values/error_handler.rb
index 6a0a82321f6..12e1366bf96 100644
--- a/app/models/calculated_values/error_handler.rb
+++ b/app/models/calculated_values/error_handler.rb
@@ -108,23 +108,14 @@ module CalculatedValues
calculated_field = calculated_fields.find { it.id == custom_field_id }
return [] unless calculated_field
- direct_missing = calculated_field.formula_referenced_custom_field_ids & cf_ids_with_missing_values
- indirect_missing = find_indirect_missing_values(calculated_field)
-
- direct_missing + indirect_missing
- end
-
- def find_indirect_missing_values(calculated_field)
- cf_ids_with_results = calculation_values.filter_map { |cf_id, v| to_id(cf_id) unless v.nil? }
- cf_ids_in_formula_without_result = calculated_field.formula_referenced_custom_field_ids - cf_ids_with_results
-
- cf_ids_in_formula_without_result.filter do |ref_id|
- calculated_fields.any? { it.id == ref_id }
- end
+ calculated_field.formula_referenced_custom_field_ids & cf_ids_with_missing_values
end
+ # Returns a list of all custom field ids that could not compute a value.
def cf_ids_with_missing_values
- @cf_ids_with_missing_values ||= given_values.filter_map { |k, v| to_id(k) if v.nil? }
+ @cf_ids_with_missing_values ||= given_values.merge(calculation_values)
+ .merge(calculation_errors)
+ .filter_map { |k, v| to_id(k) unless v.is_a?(Numeric) }
end
def create_error_records!(error_contexts)
diff --git a/spec/models/acts_as_customizable/calculated_value_spec.rb b/spec/models/acts_as_customizable/calculated_value_spec.rb
index bff5881d7f0..0f9de5e67cf 100644
--- a/spec/models/acts_as_customizable/calculated_value_spec.rb
+++ b/spec/models/acts_as_customizable/calculated_value_spec.rb
@@ -438,7 +438,10 @@ RSpec.describe ActsAsCustomizable::CalculatedValue, with_flag: { calculated_valu
expect(cv3.calculated_value_errors.where(customized: project)).to be_empty
+ # Directly missing cf_int
expect_calculated_value_error(cv1, project, "ERROR_MISSING_VALUE", cf_int.name)
+
+ # Missing a value for cv1, which itself is missing cf_int and thus has no value
expect_calculated_value_error(cv2, project, "ERROR_MISSING_VALUE", cv1.name)
end
end