Convert attributes' empty strings to nil before doing object lookup in ImportExport::BaseObjectBuilder

There is a bug with Group/Project Import/Export's BaseObjectBuilder where it is not properly able to find existing objects like labels/milestones if those relations have empty strings as values for attributes (for example, description).

The following scenario will illustrate the problem better:

  1. Source Group/Project has a label that is being used on an issue board.
  2. This label has an empty string as a description
  3. When serialized to json and exported, label's description is going to be "description" => "", as expected
  4. On Import, when the label is created, rails converts description: "" to description: nil and saves it.
  5. During import when creating a board, we need to find and associate already created label with newly created board (instead of creating one).
  6. GroupObjectBuilder uses 4 attributes to find an existing object. group_id/title/description/created_at. The lookup uses description: "" and fails to find the right label, since nil != "", which leads to a relation creation failure (since it tries to create a label with the same title, and fails). https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/import_export/group_object_builder.rb#L28-33

Converting any empty strings to nil before doing a lookup is going to solve this problem.

This is currently not a problem for Project Import, because it does not rely on description to do object lookup https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/import_export/group_project_object_builder.rb#L41-41

Edited by Haris Delalić