Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Request Merge Fails for GitLab v16.1.5-ee #2719

Closed
mnazir23 opened this issue Nov 9, 2023 · 3 comments
Closed

Merge Request Merge Fails for GitLab v16.1.5-ee #2719

mnazir23 opened this issue Nov 9, 2023 · 3 comments

Comments

@mnazir23
Copy link

mnazir23 commented Nov 9, 2023

Description of the problem, including code/CLI snippet

Hello,

We recently upgraded to GitLab v16.1.5-ee and since then when running the code (using the python-gitlab client) to merge a merge request, we have been getting some erratic behavior.

The merge() function has been failing with the following errors

  • 422: Branch cannot be merged
  • 405: Method not allowed.

Sometimes the function works and the merge request gets merged.

Every other functionality including creating merge requests, creating groups, projects, performing commits etc. are working.

Code Snippet

merge_request = project.mergerequests.create({
                    'source_branch': 'test',
                    'target_branch': 'main',
                    'title': 'Merge Test to Main',
                    'description': 'Merge request from test branch to main branch'
                })

time.sleep(2)
merge_request.merge()

Expected Behavior

Merge request should get merged every time.

Actual Behavior

Getting 422 or 405 errors.
Rarely, the merge request gets merged too.

Specifications

  • python-gitlab version: 4.1.1
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): 16.1.5-ee
@JohnVillalovos
Copy link
Member

I doubt this is an issue with python-gitlab. python-gitlab is just a simple wrapper around the API. It doesn't do much but send the API to the GitLab instance.

Of course it could be an issue with python-gitlab but I doubt it.

You might try doing gl.enable_debug() to enable debug output and see the HTTP requests.

@nejch
Copy link
Member

nejch commented Nov 9, 2023

@mnazir23 I agree with @JohnVillalovos here. GitLab has been moving to processing MR workloads asynchronously and we can't work around this as a client making API requests. See for example also https://docs.gitlab.com/ee/api/merge_requests.html#empty-api-fields-for-new-merge-requests.

You should probably always refresh and check the merge_status of a merge request before the merge operation. At work I've seen this issue with multiple tools dealing with the merge request API, not just python-gitlab.

@mnazir23
Copy link
Author

@nejch thank you for that recommendation, yes I am checking the merge status now.

I will close this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants