GitLab API merge endpoint returns 405 when it should return 406 due to merge conflict

Summary

Trying to merge a merge request containing a merge conflict via the GitLab API results in HTTP status 405 Method Not Allowed instead of HTTP status 406 Branch cannot be merged.

Steps to reproduce

  1. Create two merge requests editing the same code line
  2. Merge one of them
  3. Try to merge the second one via the GitLab API

Example Project

This is an example merge request: tjaacks/test!11

It can't be merged due to a merge conflict.

What is the current bug behavior?

Trying to merge the above merge request gets HTTP status 405 Method Not Allowed.

What is the expected correct behavior?

According to the documentation I should get HTTP status 406 Branch cannot be merged. Excerpt from the docs:

HTTP Status Message Reason
405 Method Not Allowed The merge request cannot be accepted because it is Draft, Closed, Pipeline Pending Completion, or Failed. Success is required.
406 Branch cannot be merged The branch has conflicts and cannot be merged.

None of the listed reasons for the 405 status is true for the example merge request above. I do not have any pipelines configured and the merge request is neither Draft nor Closed. The only reason why it cannot be merged is a merge conflict, so according to the documentation I should get a 406 status.

Output of checks

This bug happens on GitLab.com.