From e72d6c3fd4fd4bba4ea06f51b34c4d376acc0ad7 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Tue, 29 Nov 2016 12:04:09 +0100 Subject: [PATCH] Fixed race condtion while importing history types for the first time. --- lib/import/otrs/history.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/import/otrs/history.rb b/lib/import/otrs/history.rb index 742bca834..18d8d86fe 100644 --- a/lib/import/otrs/history.rb +++ b/lib/import/otrs/history.rb @@ -1,9 +1,11 @@ +# rubocop:disable Style/ClassVars module Import module OTRS class History def initialize(history) init_callback(history) + ensure_history_attribute add end @@ -16,6 +18,18 @@ module Import def add ::History.add(@history_attributes) end + + # make sure that no other thread is importing just the same + # history attribute which causes a ActiveRecord::RecordNotUnique + # exception we (currently) can't handle otherwise + def ensure_history_attribute + history_attribute = @history_attributes[:history_attribute] + return if !history_attribute + @@created_history_attributes ||= {} + return if @@created_history_attributes[history_attribute] + @@created_history_attributes[history_attribute] = true + ::History.attribute_lookup(history_attribute) + end end end end