Skip to content

Merge request approve()/unapprove() methods breaks the original Merge Request object #2274

Closed as not planned

Description

@dahorak

Description of the problem, including code/CLI snippet

Approving/unapproving merge request using approve() or unapprove() methods breaks the merge request object and no further operation is then possible:

In [5]: mr = pr.mergerequests.get(mr_number)

In [6]: mr
Out[6]: <ProjectMergeRequest iid:4>

In [7]: mr.approve()
Out[7]: 
{...truncated...}

In [8]: mr
Out[8]: <ProjectMergeRequest iid:None>

In [9]: mr.unapprove()
---------------------------------------------------------------------------
GitlabHttpError                           Traceback (most recent call last)
~/RedHat/OCS/ocs-ci/venv/lib64/python3.9/site-packages/gitlab/exceptions.py in wrapped_f(*args, **kwargs)
    324             try:
--> 325                 return f(*args, **kwargs)
    326             except GitlabHttpError as e:

~/RedHat/OCS/ocs-ci/venv/lib64/python3.9/site-packages/gitlab/v4/objects/merge_requests.py in unapprove(self, **kwargs)
    308 
--> 309         server_data = self.manager.gitlab.http_post(path, post_data=data, **kwargs)
    310         if TYPE_CHECKING:

~/RedHat/OCS/ocs-ci/venv/lib64/python3.9/site-packages/gitlab/client.py in http_post(self, path, query_data, post_data, raw, files, **kwargs)
   1014 
-> 1015         result = self.http_request(
   1016             "post",

~/RedHat/OCS/ocs-ci/venv/lib64/python3.9/site-packages/gitlab/client.py in http_request(self, verb, path, query_data, post_data, raw, streamed, files, timeout, obey_rate_limit, retry_transient_errors, max_retries, **kwargs)
    797 
--> 798             raise gitlab.exceptions.GitlabHttpError(
    799                 response_code=result.status_code,

GitlabHttpError: 404: 404 Not found

The above exception was the direct cause of the following exception:

GitlabMRApprovalError                     Traceback (most recent call last)
<ipython-input-13-120d1f7d6349> in <module>
----> 1 mr.unapprove()

~/RedHat/OCS/ocs-ci/venv/lib64/python3.9/site-packages/gitlab/cli.py in wrapped_f(*args, **kwargs)
     69         @functools.wraps(f)
     70         def wrapped_f(*args: Any, **kwargs: Any) -> Any:
---> 71             return f(*args, **kwargs)
     72 
     73         # in_obj defines whether the method belongs to the obj or the manager

~/RedHat/OCS/ocs-ci/venv/lib64/python3.9/site-packages/gitlab/exceptions.py in wrapped_f(*args, **kwargs)
    325                 return f(*args, **kwargs)
    326             except GitlabHttpError as e:
--> 327                 raise error(e.error_message, e.response_code, e.response_body) from e
    328 
    329         return cast(__F, wrapped_f)

GitlabMRApprovalError: 404: 404 Not found

On line Out[6], the mr object contain correct iid:4, but after calling mr.approve() (line Out[8]), the iid of the mr object is changed to None and any followup action on the same object fails with long traceback.

Expected Behavior

It is possible to perform additional actions on Merge Request object after approve() or unapprove() is performed (similarly as it is possible to add multiple comments or merge the request and perform further tasks).

Actual Behavior

Calling approve() or unapprove() change the merge request object in the way, that it is not possible to perform further action.

Specifications

  • python-gitlab version: 3.9.0
  • API version you are using (v3/v4): probably v4
  • Gitlab server version (or gitlab.com): 15.3.3

Activity

  1. nejch commented on Sep 15, 2022

    @nejch
    Member

    This is essentially a duplicate of/related to #2007.

    But I think our behavior relying on server responses on save might be unexpected enough that we should revisit #1443

    I don't know if this changed in GitLab's API at some point but the approve endpoint does not return what GitLab's docs say, it returns something like this:

    {'approved': True,
     'approved_by': [{'user': {'avatar_url': '***',
                               'id': 101,
                               'name': 'Nejc Habjan',
                               'state': 'active',
                               'username': 'nejc',
                               'web_url': 'https://gitlab.example.com/nejc'}}],
     'user_can_approve': False,
     'user_has_approved': True}
  2. nejch commented on Sep 24, 2022

    @nejch
    Member

    @dahorak I've started a bit more discussion in #2007, please follow progress there 🙇

  3. locked as resolved and limited conversation to collaborators on Sep 25, 2023
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions