Skip to content

Convert empty strings to nil in ImportExport::BaseObjectBuilder

What does this MR do?

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

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by George Koltsov

Merge request reports

Loading