Commit c2a6a581 authored by George Koltsov's avatar George Koltsov

Truncate error messages for failed Group Import

parent 83b25c71
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
class GroupImportState < ApplicationRecord class GroupImportState < ApplicationRecord
self.primary_key = :group_id self.primary_key = :group_id
MAX_ERROR_LENGTH = 255
belongs_to :group, inverse_of: :import_state belongs_to :group, inverse_of: :import_state
belongs_to :user, optional: false belongs_to :user, optional: false
...@@ -30,7 +32,7 @@ class GroupImportState < ApplicationRecord ...@@ -30,7 +32,7 @@ class GroupImportState < ApplicationRecord
after_transition any => :failed do |state, transition| after_transition any => :failed do |state, transition|
last_error = transition.args.first last_error = transition.args.first
state.update_column(:last_error, last_error) if last_error state.update_column(:last_error, last_error.truncate(MAX_ERROR_LENGTH)) if last_error
end end
end end
......
---
title: Fix failed group imports getting stuck by long error messages
merge_request: 48989
author:
type: fixed
...@@ -70,4 +70,24 @@ RSpec.describe GroupImportState do ...@@ -70,4 +70,24 @@ RSpec.describe GroupImportState do
end end
end end
end end
context 'when import failed' do
context 'when error message is present' do
it 'truncates error message' do
group_import_state = build(:group_import_state, :started)
group_import_state.fail_op('e' * 300)
expect(group_import_state.last_error.length).to eq(255)
end
end
context 'when error message is missing' do
it 'has no error message' do
group_import_state = build(:group_import_state, :started)
group_import_state.fail_op
expect(group_import_state.last_error).to be_nil
end
end
end
end end
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