Cannot delete scope (environment) of feature flag through the API
Summary
It is not possible to remove a feature flag strategies.scopes through the API. This is where the environments in which the feature flag is active are stored.
Steps to reproduce
Go to a project's Deployment > Environment, create few environments. Then head to Deployments > Feature Flags, create a feature flag and attach those environments to its default strategy.
Once that's set up we can query that feature flag through the API to see its details:
; curl "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/feature_flags/test-flag-1" \
--header "PRIVATE-TOKEN: $GITLAB_API_TOKEN"
# response
{
"name": "test-flag-1",
"description": "Description",
"active": true,
"version": "new_version_flag",
"created_at": "2022-09-08T07:23:17.070Z",
"updated_at": "2022-09-08T10:24:01.195Z",
"scopes": [],
"strategies": [{
"id": 27778,
"name": "default",
"parameters": {},
"scopes": [{
"id": 66929,
"environment_scope": "test-env-1"
}, {
"id": 66930,
"environment_scope": "test-env-2"
}, {
"id": 66931,
"environment_scope": "test-env-3"
}]
}]
}
Try to update the environment_scope array, BY REMOVING one or several scopes there:
curl -X PUT "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/feature_flags/test-flag-1" \
--header "PRIVATE-TOKEN: $GITLAB_API_TOKEN" \
--header "Content-type: application/json" \
--data @- << EOF
{
"name": "test-flag-1",
"description": "Updated description",
"version": "new_version_flag",
"strategies": [{
"id": 27778,
"name": "default",
"parameters": {},
"scopes": [{
"environment_scope": "test-env-1",
"id": 66929
}]
}]
}
EOF
#response
{
"name": "test-flag-1",
"description": "Updated description",
"active": true,
"version": "new_version_flag",
"created_at": "2022-09-08T07:23:17.070Z",
"updated_at": "2022-09-08T11:43:55.561Z",
"scopes": [],
"strategies": [{
"id": 27778,
"name": "default",
"parameters": {},
"scopes": [{
"id": 66929,
"environment_scope": "test-env-1"
}, {
"id": 66930,
"environment_scope": "test-env-2"
}, {
"id": 66931,
"environment_scope": "test-env-3"
}]
}]
}
The description will be updated, but the strategies.scopes array will not be updated.
Link to the documentation: https://docs.gitlab.com/ee/api/feature_flags.html#update-a-feature-flag
What is the current bug behavior?
The strategies.scope array stays the same, instead of being upated.
What is the expected correct behavior?
We should see a response such as this one, which has a strategies.scopes array with only the element sent on the request:
{
"name": "test-flag-1",
"description": "Updated description",
"active": true,
"version": "new_version_flag",
"created_at": "2022-09-08T07:23:17.070Z",
"updated_at": "2022-09-08T11:43:55.561Z",
"scopes": [],
"strategies": [{
"id": 27778,
"name": "default",
"parameters": {},
"scopes": [{
"id": 66929,
"environment_scope": "test-env-1"
}]
}]
}
Output of checks
This bug happens on GitLab.com
Possible fixes
If have found relevant MR's and it seems that deleting feature flag environment scopes is behing a feature flag that has not been turned on ? Or that's maybe old stuff, but in case:
!18200 (merged) !19677 (merged)
It is possible to add new environment to the strategies.scope object, but not remove them.