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

Add meaningful error message when the journalized.journal_id is not provided

Dombi Attilaed3e4b5b67d5
diff --git a/app/models/journable/with_historic_attributes/loader.rb b/app/models/journable/with_historic_attributes/loader.rb
index 7e24d6363a3..385dfb350ec 100644
--- a/app/models/journable/with_historic_attributes/loader.rb
+++ b/app/models/journable/with_historic_attributes/loader.rb
@@ -61,7 +61,16 @@ class Journable::WithHistoricAttributes
end
def load_custom_values(journalized = journables)
- journals_by_id = load_journals_by_id(journalized.map(&:journal_id))
+ journal_ids = begin
+ journalized.map(&:journal_id)
+ rescue NoMethodError
+ raise ArgumentError,
+ 'The provided journalized items do not have a journal_id included. ' \
+ 'Please load them via any of the Journable::Timestamps#at_timestamp method. ' \
+ 'ie: WorkPackage.at_timestamp(1.day.ago) or WorkPackage.find(1).at_timestamp(1.day.ago)'
+ end
+
+ journals_by_id = load_journals_by_id(journal_ids)
journalized.each do |work_package|
journal = journals_by_id[work_package.journal_id]