Skip to content

"Prevent MR approvals by the author" is ignored unless checked, saved, and unchecked

Summary

If a new merge request approval rule it will act as though "Prevent MR approvals by the author" is togged on. This can be fixed by toggling it on and off.

The bug seems to be a number of the approval parameters are initialised as null. I think if these are set initialised correctly this should fix the bug. The parameters are shown in the API responses below!

This may relate to the discussion in #36978 (closed), and the underlying issue appears to be touched upon in the comments of #36486 (closed). But I don't think either of these explicitly describe this bug behaviour.

Steps to reproduce

During these steps it is worth checking the /approvals API route

  1. Create a new project with a simple README.md file
  2. Go to Settings->Merge request approvals and set a new approval rule where you are one of the approvers. The bug behaviour is more clear if you add more than one approver. Do not touch the check boxes below at this point
  3. Create a new MR. Can be anything. I created a change to the read me from the WebIDE. You will be listed in the approval rule as expected (as "Prevent MR approvals by the author" is off by default)
  4. Once created check the approval rule. You will not be listed as an approver any more

Example Project

julianstirling/mr-aproval-test!1 <- this is no longer in the bug state as I have done the further steps given below.

What is the current bug behaviour?

Initial behaviour

When you first create the project run the following API request:

curl --header "Private-Token: YouCanNotHaveMyToken" -X GET https://gitlab.com/api/v4/projects/123456789/approvals

The response is:

{"approvers":[],
 "approver_groups":[],
 "approvals_before_merge":0,
 "reset_approvals_on_push":true,
 "disable_overriding_approvers_per_merge_request":null,
 "merge_requests_author_approval":null,
 "merge_requests_disable_committers_approval":null,
 "require_password_to_approve":null
}

The nulls do not seem right to me as the tick boxes have values. This might be as expected as there are no approval rules. However, once you make the approval rule this remains unchanged. As mentioned above you are not listed on the approval (but approval is implied): image

Change behaviour

If you then go to settings and set "Prevent MR approvals by the author" to True, and save the changes. You will still not be listed on that rule as expected. UI changes slightly:
image
API:

 {"approvers":[],
  "approver_groups":[],
  "approvals_before_merge":0,
  "reset_approvals_on_push":true,
  "disable_overriding_approvers_per_merge_request":true,
  "merge_requests_author_approval":false,
  "merge_requests_disable_committers_approval":false,
  "require_password_to_approve":false
  }

Action to fix (Workaround)

Now return to settings and set "Prevent MR approvals by the author" to False, and save the changes. Everything now works as expected:
image
API:

{"approvers":[],
  "approver_groups":[],
  "approvals_before_merge":0,
  "reset_approvals_on_push":true,
  "disable_overriding_approvers_per_merge_request":true,
  "merge_requests_author_approval":true,
  "merge_requests_disable_committers_approval":false,
  "require_password_to_approve":false
  }

What is the expected correct behaviour?

Implied by above 🙂

Relevant logs and/or screenshots

See API responses above

Output of checks

This bug happens on GitLab.com