Update Import failures to include subrelation errors

What does this MR do and why?

Change 1

This MR updates file-based Import as well as GitLab Direct Transfer to include subrelation errors in the main error message if a relation failed to import. For example: assume an issue that has a collection of notes with each having a collection of award emojis. If such issue has invalid notes and we try to import said issue, the following error is presented:

issue = Project.last.issues.new(
  title: 'test',
  author: User.first,
  notes: [Note.new(
    award_emoji: [AwardEmoji.new(name: 'test')]
)])
      
issue.validate
issue.errors.full_messages

=> ["Notes is invalid"]

As you can see a "Notes is invalid" is not a very descriptive error message, not very helpful to the user. We want to be able to see subrelation errors as well and present it back to the user, so it helps with debugging purposes & reduces feedback loop.

With changes in this MR the error message will include subrelation error messages:

Gitlab::Import::Errors.merge_nested_errors(issue)

issue.errors.full_messages

=> ["Notes is invalid",
 "Award emoji is invalid",
 "Note can't be blank",
 "Project can't be blank",
 "Noteable can't be blank",
 "Author can't be blank",
 "Project does not match noteable project",
 "User can't be blank",
 "Awardable can't be blank",
 "Name is not a valid emoji name"]      

Change 2

While working on this MR, I noticed GitLab Direct Transfer and it's NdjsonPipeline does not utilize RelationObjectSaver class when persisting relations. This is an oversight and it should be utilized, similarly to what we do in file-based Import's RelationTreeRestorer.

Mentions #387782 (closed)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by George Koltsov

Merge request reports

Loading