Commit 22c1c980 authored by Rémy Coutable's avatar Rémy Coutable

Fix ApplicationSetting development seed

It could happen that there's a cached (in Redis) ApplicationSetting
record, and calling
`Gitlab::CurrentSettings.current_application_settings` only returns it
instead of creating a new DB record, which makes the
`ApplicationSetting.current_without_cache.update!` call fail.
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 6c8a13da
...@@ -259,7 +259,9 @@ class ApplicationSetting < ApplicationRecord ...@@ -259,7 +259,9 @@ class ApplicationSetting < ApplicationRecord
after_commit :expire_performance_bar_allowed_user_ids_cache, if: -> { previous_changes.key?('performance_bar_allowed_group_id') } after_commit :expire_performance_bar_allowed_user_ids_cache, if: -> { previous_changes.key?('performance_bar_allowed_group_id') }
def self.create_from_defaults def self.create_from_defaults
super transaction(requires_new: true) do
super
end
rescue ActiveRecord::RecordNotUnique rescue ActiveRecord::RecordNotUnique
# We already have an ApplicationSetting record, so just return it. # We already have an ApplicationSetting record, so just return it.
current_without_cache current_without_cache
......
...@@ -159,8 +159,8 @@ module Projects ...@@ -159,8 +159,8 @@ module Projects
log_message << " Project ID: #{@project.id}" if @project&.id log_message << " Project ID: #{@project.id}" if @project&.id
Rails.logger.error(log_message) Rails.logger.error(log_message)
if @project if @project && @project.persisted? && @project.import_state
@project.import_state.mark_as_failed(message) if @project.persisted? && @project.import? @project.import_state.mark_as_failed(message)
end end
@project @project
......
# frozen_string_literal: true # frozen_string_literal: true
puts "Creating the default ApplicationSetting record.".color(:green) puts "Creating the default ApplicationSetting record.".color(:green)
Gitlab::CurrentSettings.current_application_settings ApplicationSetting.create_from_defaults
# Details https://gitlab.com/gitlab-org/gitlab-ce/issues/46241 # Details https://gitlab.com/gitlab-org/gitlab-ce/issues/46241
puts "Enable hashed storage for every new projects.".color(:green) puts "Enable hashed storage for every new projects.".color(:green)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment