diff options
Diffstat (limited to 'lib/bulk_imports/ndjson_pipeline.rb')
-rw-r--r-- | lib/bulk_imports/ndjson_pipeline.rb | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/lib/bulk_imports/ndjson_pipeline.rb b/lib/bulk_imports/ndjson_pipeline.rb index 05d724a5e42..3c392910c1f 100644 --- a/lib/bulk_imports/ndjson_pipeline.rb +++ b/lib/bulk_imports/ndjson_pipeline.rb @@ -16,8 +16,6 @@ module BulkImports return unless relation_hash - relation_definition = import_export_config.top_relation_tree(relation) - relation_object = deep_transform_relation!(relation_hash, relation, relation_definition) do |key, hash| relation_factory.create( relation_index: relation_index, @@ -35,8 +33,29 @@ module BulkImports relation_object end - def load(_, object) - object&.save! + def load(_context, object) + return unless object + + if object.new_record? + saver = Gitlab::ImportExport::Base::RelationObjectSaver.new( + relation_object: object, + relation_key: relation, + relation_definition: relation_definition, + importable: portable + ) + + saver.execute + + capture_invalid_subrelations(saver.invalid_subrelations) + else + if object.invalid? + Gitlab::Import::Errors.merge_nested_errors(object) + + raise(ActiveRecord::RecordInvalid, object) + end + + object.save! + end end def deep_transform_relation!(relation_hash, relation_key, relation_definition, &block) @@ -104,6 +123,22 @@ module BulkImports def portable_class_sym portable.class.to_s.downcase.to_sym end + + def relation_definition + import_export_config.top_relation_tree(relation) + end + + def capture_invalid_subrelations(invalid_subrelations) + invalid_subrelations.each do |record| + BulkImports::Failure.create( + bulk_import_entity_id: tracker.entity.id, + pipeline_class: tracker.pipeline_name, + exception_class: 'RecordInvalid', + exception_message: record.errors.full_messages.to_sentence.truncate(255), + correlation_id_value: Labkit::Correlation::CorrelationId.current_or_new_id + ) + end + end end end end |