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

Don't break the migration if the user's language is invalid

Oliver Günther66bf56d405bf
diff --git a/db/migrate/20190710132957_rename_my_page_widgets.rb b/db/migrate/20190710132957_rename_my_page_widgets.rb
index b12f66bd315..8c449ec6b2c 100644
--- a/db/migrate/20190710132957_rename_my_page_widgets.rb
+++ b/db/migrate/20190710132957_rename_my_page_widgets.rb
@@ -3,8 +3,14 @@ class RenameMyPageWidgets < ActiveRecord::Migration[5.2]
reset_column_information
Grids::MyPage.eager_load(:widgets, user: :preference).each do |page|
- I18n.with_locale(page.user&.language.presence || 'en') do
+ begin
+ I18n.with_locale(page.user&.language.presence || 'en') do
+ page.widgets.each(&method(:update_widget))
+ end
+ rescue I18n::InvalidLocale => e
+ Rails.logger.warn "Failed to use user locale from #{page.user.inspect}: #{e} #{e.message}. Correcting"
page.widgets.each(&method(:update_widget))
+ page.user&.update_column(:language, 'en')
end
end
end