Skip to content

ProjectMergeRequestApprovalRule.save() throws 404 #2548

Closed

Description

@jwbaker

Description of the problem, including code/CLI snippet

gl.project.get(proj_id).merge_requests.get(mr_iid).approval_rules.get(rule_id).save()

This example is an MVP example; actually making changes to the rule object before calling .save() doesn't change the behaviour

Expected Behavior

The function should succeed silently, returning None

Actual Behavior

gitlab.exceptions.GitlabUpdateError: 404: 404 Not found is thrown. Trying it with debug mode on, it appears as though the root cause of the issue is that when the CLI invokes /projects/:id/merge_requests/:merge_request_iid/approval_rules/:approval_rule_id in the API, :id (i.e. project ID) is passed where the URL expects :approval_rule_id, as can be seen from this debug output (anonymized to remove sensitive information)

>>> rule.save()
DEBUG:urllib3.connectionpool:Resetting dropped connection: mygitlab.example.com
send: b'PUT /api/v4/projects/93/merge_requests/1/approval_rules/93 HTTP/1.1\r\nHost: mygitlab.example.com\r\nUser-Agent: python-gitlab/3.14.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nPRIVATE-TOKEN: TOKEN\r\nContent-type: application/json\r\nContent-Length: 768\r\n\r\n'
send: b'{"id": "93", "merge_request_iid": "1", "approval_rule_id": 89, "name": "testrule", "approvals_required": 1, "users": ["{\\"id\\": 168, \\"username\\": \\"myusername\\", \\"name\\": \\"My Name\\", \\"state\\": \\"active\\", \\"avatar_url\\": \\"https://secure.gravatar.com/avatar/8306d9f17d1c91970c2447b61c7a9f29?s=80&d=identicon\\", \\"web_url\\": \\"https://mygitlab.example.com/myusername\\", \\"created_at\\": \\"2023-03-29T14:30:13.371Z\\", \\"bio\\": \\"\\", \\"location\\": null, \\"public_email\\": null, \\"skype\\": \\"\\", \\"linkedin\\": \\"\\", \\"twitter\\": \\"\\", \\"website_url\\": \\"\\", \\"organization\\": null, \\"job_title\\": \\"\\", \\"pronouns\\": null, \\"bot\\": false, \\"work_information\\": null, \\"followers\\": 0, \\"following\\": 0, \\"is_followed\\": false, \\"local_time\\": null}"]}'
reply: 'HTTP/1.1 404 Not Found\r\n'

Specifications

  • python-gitlab version: 3.14.0
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): 15.7.2-ee

Activity

  1. added
    EEIssues related to the enterprise version of GitLab
    on Apr 17, 2023
  2. nejch commented on Apr 17, 2023

    @nejch
    Member

    Looks like we have some old code here:

    https://github.com/python-gitlab/python-gitlab/blame/eb54adf2fe7d3c68dcb6021065e51ba33b7bbc04/gitlab/v4/objects/merge_request_approvals.py#L155

    We might be able to just get rid of that custom save method, things might be more consistent these days. I don't use Premium features personally, so this needs some digging on why we even have that in the code.

  3. added 3 commits that reference this issue on Jan 22, 2024
    acab43c
    7326a77
    a168c63
  4. Sjord commented on Jan 22, 2024

    @Sjord
    Contributor

    Indeed the used identifier is incorrect. It would perform a call to /api/v4/projects/1/merge_requests/1/approval_rules/3 instead of /api/v4/projects/1/merge_requests/1/approval_rules/1 when saving.

    The unit test here does not catch that, since the project ID, merge request ID, and approval rule ID are all 1, so a mix up is not detected.

    Docs for this feature:

  5. added a commit that references this issue on Jan 28, 2024
    56266d8
  6. added a commit that references this issue on Jan 30, 2024
    7e80daa
  7. jarodwilson commented on May 13, 2024

    @jarodwilson
    Contributor

    We're actively encountering this bug ourselves, was there a plan to get #2773 merged?

  8. added 2 commits that reference this issue on May 13, 2024
    7daa18f
    7e314a1
  9. added a commit that references this issue on May 13, 2024
    b8b3849
  10. JohnVillalovos commented on May 14, 2024

    @JohnVillalovos
    Member

    We're actively encountering this bug ourselves, was there a plan to get #2773 merged?

    It is now merged and a new release of python-gitlab was made.

  11. locked as resolved and limited conversation to collaborators on May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    EEIssues related to the enterprise version of GitLabbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions