Skip to content

gitlab project-merge-request-approval-rule list throws a KeyError "approval_rule_id" error. #2065

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

Closed
MaximeCheramy opened this issue Jun 10, 2022 · 1 comment · Fixed by #2066
Labels

Comments

@MaximeCheramy
Copy link

MaximeCheramy commented Jun 10, 2022

Description of the problem, including code/CLI snippet

$ gitlab project-merge-request-approval-rule list --mr-iid 1 --project-id foo/bar

Expected Behavior

A list of approval rules

Actual Behavior

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/gitlab/base.py", line 107, in __getattr__
    return self.__dict__["_updated_attrs"][name]
KeyError: 'approval_rule_id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/gitlab/base.py", line 110, in __getattr__
    value = self.__dict__["_attrs"][name]
KeyError: 'approval_rule_id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/gitlab/base.py", line 130, in __getattr__
    return self.__dict__["_parent_attrs"][name]
KeyError: 'approval_rule_id'

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

Traceback (most recent call last):
  File "/usr/local/bin/gitlab", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/dist-packages/gitlab/cli.py", line 362, in main
    gitlab.v4.cli.run(gl, what, action, args_dict, verbose, output, fields)
  File "/usr/local/lib/python3.9/dist-packages/gitlab/v4/cli.py", line 515, in run
    printer.display_list(data, fields, verbose=verbose)
  File "/usr/local/lib/python3.9/dist-packages/gitlab/v4/cli.py", line 483, in display_list
    self.display(get_dict(obj, fields), verbose=verbose, obj=obj)
  File "/usr/local/lib/python3.9/dist-packages/gitlab/v4/cli.py", line 461, in display
    id = getattr(obj, obj._id_attr)
  File "/usr/local/lib/python3.9/dist-packages/gitlab/base.py", line 146, in __getattr__
    raise AttributeError(message) from exc
AttributeError: 'ProjectMergeRequestApprovalRule' object has no attribute 'approval_rule_id'

<class 'gitlab.v4.objects.merge_request_approvals.ProjectMergeRequestA
pprovalRule'> was created via a list() call and only a subset of the
data may be present. To ensure all data is present get the object
using a get(object.id) call. For more details, see:

https://python-gitlab.readthedocs.io/en/v3.5.0/faq.html#attribute-error-list

Specifications

  • python-gitlab version: 3.5.0
  • API version you are using (v3/v4): not sure, the default one
  • Gitlab server version (or gitlab.com): 14.10
@JohnVillalovos
Copy link
Member

My very quick initial guess is likely these two lines should be removed:

_id_attr = "approval_rule_id"
_repr_attr = "approval_rule"

@nejch What do you think?

JohnVillalovos added a commit that referenced this issue Jun 11, 2022
Using the CLI the command:
   gitlab project-merge-request-approval-rule list --mr-iid 1 --project-id foo/bar

Would raise an exception. This was due to the fact that `_id_attr` and
`_repr_attr` were set for keys which are not returned in the response.

Closes: #2065
JohnVillalovos added a commit that referenced this issue Jun 11, 2022
Using the CLI the command:
   gitlab project-merge-request-approval-rule list --mr-iid 1 --project-id foo/bar

Would raise an exception. This was due to the fact that `_id_attr` and
`_repr_attr` were set for keys which are not returned in the response.

Closes: #2065
JohnVillalovos added a commit that referenced this issue Jun 11, 2022
Using the CLI the command:
   gitlab project-merge-request-approval-rule list --mr-iid 1 --project-id foo/bar

Would raise an exception. This was due to the fact that `_id_attr` and
`_repr_attr` were set for keys which are not returned in the response.

Closes: #2065
JohnVillalovos added a commit that referenced this issue Jun 11, 2022
Using the CLI the command:
   gitlab project-merge-request-approval-rule list --mr-iid 1 --project-id foo/bar

Would raise an exception. This was due to the fact that `_id_attr` and
`_repr_attr` were set for keys which are not returned in the response.

This is an EE feature so we can't functional test it.

Closes: #2065
JohnVillalovos added a commit that referenced this issue Jun 11, 2022
Using the CLI the command:
   gitlab project-merge-request-approval-rule list --mr-iid 1 --project-id foo/bar

Would raise an exception. This was due to the fact that `_id_attr` and
`_repr_attr` were set for keys which are not returned in the response.

Add a unit test which shows the `repr` function now works. Before it
did not.

This is an EE feature so we can't functional test it.

Closes: #2065
JohnVillalovos added a commit that referenced this issue Jun 11, 2022
Using the CLI the command:
   gitlab project-merge-request-approval-rule list --mr-iid 1 --project-id foo/bar

Would raise an exception. This was due to the fact that `_id_attr` and
`_repr_attr` were set for keys which are not returned in the response.

Add a unit test which shows the `repr` function now works. Before it
did not.

This is an EE feature so we can't functional test it.

Closes: #2065
@nejch nejch added the bug label Jun 13, 2022
JohnVillalovos added a commit that referenced this issue Jun 18, 2022
Using the CLI the command:
   gitlab project-merge-request-approval-rule list --mr-iid 1 --project-id foo/bar

Would raise an exception. This was due to the fact that `_id_attr` and
`_repr_attr` were set for keys which are not returned in the response.

Add a unit test which shows the `repr` function now works. Before it
did not.

This is an EE feature so we can't functional test it.

Closes: #2065
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants