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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#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.rbindex 6a0a82321f6..12e1366bf96 100644--- a/app/models/calculated_values/error_handler.rb+++ b/app/models/calculated_values/error_handler.rb@@ -108,23 +108,14 @@ module CalculatedValuescalculated_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_valuesend+ # 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) }enddef 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.rbindex 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_valuexpect(cv3.calculated_value_errors.where(customized: project)).to be_empty+ # Directly missing cf_intexpect_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 valueexpect_calculated_value_error(cv2, project, "ERROR_MISSING_VALUE", cv1.name)endend