GitLab Migration validate entities path in the backend
Summary
GitLab Migration doesn't validate the entity's path uniqueness in the backend before creating a BulkImport record. Because of that, BulkImport created via API with a conflicting path within a namespace is accepted, which causes the migration to fail later in the process.
Ideally, the request shouldn't be accepted, and an error should be returned to the user
Steps to reproduce
- Create a group. For example:
Group 1 <path: group>
- Within the group, create a subgroup. For example:
SubGroup<path: subgroup>
- Create a BulkImport migration via API and set the destination to be the subgroup path
curl --location --request POST 'http://gdk.test:3000/api/v4/bulk_imports' \
--header 'Authorization: Bearer <TOKEN>' \
--header 'Content-Type: application/json' \
--data-raw '{
"configuration": {
"url": "http://gdk.test:3000",
"access_token": "e<TOKEN>"
},
"entities": [
{
"source_full_path": "gitlab-org",
"source_type": "group_entity",
"destination_slug": "subgroup",
"destination_namespace": "group"
}
]
}'
- The request will be accepted and the migration will fail with the error
[
{
"relation": "group",
"step": "loader",
"exception_message": "Group exists",
"exception_class": "BulkImports::Groups::Loaders::GroupLoader::GroupCreationError",
"correlation_id_value": "01GFRG9XK9SNFC3QXX0T8GYJ30",
"created_at": "2022-10-19T16:17:33.548Z",
"pipeline_class": "BulkImports::Groups::Pipelines::GroupPipeline",
"pipeline_step": "loader"
}
]
Solution
The entity path needs be validated in the backend
Edited by Magdalena Frankiewicz