Skip to content

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

Closed as not planned
@dahorak

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

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