Removing and adding branch protection REST API issue

Summary

We cannot programmatically create a GitLab project via REST API, remove initial branch protection and then re-add branch protection with correct settings.

Steps to reproduce

Example Project

What is the current bug behavior?

What is the expected correct behavior?

  • Both calls should result in a 200

Relevant logs and/or screenshots

Initial call

{
  "message": "Request failed with status code 500",
  "name": "AxiosError",
  "config": {
    "transitional": {
      "silentJSONParsing": true,
      "forcedJSONParsing": true,
      "clarifyTimeoutError": false
    },
    "transformRequest": [
      null
    ],
    "transformResponse": [
      null
    ],
    "timeout": 30000,
    "xsrfCookieName": "XSRF-TOKEN",
    "xsrfHeaderName": "X-XSRF-TOKEN",
    "maxContentLength": -1,
    "maxBodyLength": -1,
    "env": {},
    "headers": {
      "Accept": "application/json",
      "Content-Type": "application/json",
      "PRIVATE-TOKEN": "REMOVED-AS-PRIVATE",
      "User-Agent": "axios/0.27.2"
    },
    "method": "delete",
    "url": "https://gitlab.com/api/v4/projects/46695135/protected_branches/main",
    "axios-retry": {
      "retryCount": 0,
      "lastRequestTime": 1686219840672
    }
  },
  "code": "ERR_BAD_RESPONSE",
  "status": 500
}

Subsequent call

{
  "message": "Request failed with status code 404",
  "name": "AxiosError",
  "config": {
    "transitional": {
      "silentJSONParsing": true,
      "forcedJSONParsing": true,
      "clarifyTimeoutError": false
    },
    "transformRequest": [
      null
    ],
    "transformResponse": [
      null
    ],
    "timeout": 30000,
    "xsrfCookieName": "XSRF-TOKEN",
    "xsrfHeaderName": "X-XSRF-TOKEN",
    "maxContentLength": -1,
    "maxBodyLength": -1,
    "env": {},
    "headers": {
      "Accept": "application/json",
      "Content-Type": "application/json",
      "PRIVATE-TOKEN": "REMOVED-AS-PRIVATE",
      "User-Agent": "axios/0.27.2"
    },
    "method": "delete",
    "url": "https://gitlab.com/api/v4/projects/46695083/protected_branches/main",
    "axios-retry": {
      "retryCount": 3,
      "lastRequestTime": 1686219701368
    }
  },
  "code": "ERR_BAD_REQUEST",
  "status": 404
}

Output of checks

This bug happens on GitLab.com /label reproduced on GitLab.com

Results of GitLab environment info

Expand for output related to GitLab environment info

Results of GitLab application Check

Expand for output related to the GitLab application check

Possible fixes