diff options
author | Rémy Coutable <remy@rymai.me> | 2018-12-12 12:59:06 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-12-19 11:24:53 +0100 |
commit | 71672dfa6afbb374b24ae5457a58204708d948ed (patch) | |
tree | b052e1b02af0d0d6b70b704960a9fb357c3fb42d /lib/gitlab/current_settings.rb | |
parent | ffef28ccd6d37ade2c3ee3ca46679749f9cf09aa (diff) | |
download | gitlab-ce-71672dfa6afbb374b24ae5457a58204708d948ed.tar.gz |
Return an ApplicationSetting in CurrentSettings
This replaces the use of fake_application_settings with
`::ApplicationSetting.build`_from_defaults. The reason is that
`fake_application_settings` doesn't have the custom accessors that
`ApplicationSetting` has, e.g. `#commit_email_hostname`, thus this
can lead to unexpected `nil` values which comes from the database
column instead of `.default_commit_email_hostname` returned by
`ApplicationSetting#commit_email_hostname`.
Using `::ApplicationSetting.build_from_defaults` should be safe as it
doesn't try to `INSERT` a DB record, in contrary to
`::ApplicationSetting.create_from_defaults` which we used to use, and
which created issues that the introduction of
`fake_application_settings` tried to resolve (575dced5).
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib/gitlab/current_settings.rb')
-rw-r--r-- | lib/gitlab/current_settings.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb index 477f9101e98..e6c80bed5a5 100644 --- a/lib/gitlab/current_settings.rb +++ b/lib/gitlab/current_settings.rb @@ -50,7 +50,15 @@ module Gitlab # and other callers from failing, use any loaded settings and return # defaults for missing columns. if ActiveRecord::Migrator.needs_migration? - return fake_application_settings(current_settings&.attributes) + db_attributes = current_settings&.attributes || {} + column_names = ::ApplicationSetting.column_names + final_attributes = ::ApplicationSetting + .defaults + .merge(db_attributes) + .stringify_keys + .slice(*column_names) + + return ::ApplicationSetting.new(final_attributes) end return current_settings if current_settings.present? |