Skip to content

fix: catch invalid type used to initialize RESTObject #1487

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

Merged
merged 1 commit into from
Jun 10, 2021
Merged

fix: catch invalid type used to initialize RESTObject #1487

merged 1 commit into from
Jun 10, 2021

Conversation

JohnVillalovos
Copy link
Member

@JohnVillalovos JohnVillalovos commented May 31, 2021

Sometimes we have errors where we don't get a dictionary passed to
RESTObject.__init__() method. This breaks things but in confusing
ways.

Check in the __init__() method and raise an exception if it occurs.

@JohnVillalovos
Copy link
Member Author

Interested to get some feedback on this. Not sure if that is the correct exception to use.

@JohnVillalovos JohnVillalovos requested a review from nejch May 31, 2021 17:50
@codecov-commenter
Copy link

codecov-commenter commented May 31, 2021

Codecov Report

Merging #1487 (c7bcc25) into master (161bb0b) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1487   +/-   ##
=======================================
  Coverage   91.04%   91.05%           
=======================================
  Files          74       74           
  Lines        4145     4148    +3     
=======================================
+ Hits         3774     3777    +3     
  Misses        371      371           
Flag Coverage Δ
cli_func_v4 80.68% <66.66%> (-0.02%) ⬇️
py_func_v4 79.96% <66.66%> (-0.01%) ⬇️
unit 82.18% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
gitlab/base.py 89.44% <100.00%> (+0.20%) ⬆️

@nejch
Copy link
Member

nejch commented Jun 1, 2021

Is the original idea behind this due to the malformed/unexpected response we got in the 301/302 redirect issue with POST? What exactly was the traceback there? :)

@JohnVillalovos
Copy link
Member Author

JohnVillalovos commented Jun 1, 2021

Is the original idea behind this due to the malformed/unexpected response we got in the 301/302 redirect issue with POST?

Yes. When the POST got changed to a GET we end up getting a list returned.

What exactly was the traceback there? :)

Like in #1477

Traceback (most recent call last):
  File "./turris-os-milestone-rename.py", line 60, in <module>
    main()
  File "./turris-os-milestone-rename.py", line 20, in main
    issue.notes.create({'body': 'note content'})
  File "/usr/lib/python3.8/site-packages/gitlab/exceptions.py", line 287, in wrapped_f
    return f(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/gitlab/mixins.py", line 325, in create
    return self._obj_cls(self, server_data)
  File "/usr/lib/python3.8/site-packages/gitlab/base.py", line 62, in __init__
    self._create_managers()
  File "/usr/lib/python3.8/site-packages/gitlab/base.py", line 151, in _create_managers
    manager = cls(self.manager.gitlab, parent=self)
  File "/usr/lib/python3.8/site-packages/gitlab/base.py", line 290, in __init__
    self._computed_path = self._compute_path()
  File "/usr/lib/python3.8/site-packages/gitlab/base.py", line 305, in _compute_path
    data = {
  File "/usr/lib/python3.8/site-packages/gitlab/base.py", line 306, in <dictcomp>
    self_attr: getattr(self._parent, parent_attr, None)
  File "/usr/lib/python3.8/site-packages/gitlab/base.py", line 80, in __getattr__
    value = self.__dict__["_attrs"][name]
TypeError: list indices must be integers or slices, not str

Copy link
Member

@nejch nejch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks! Just a small thought from my side.

@JohnVillalovos JohnVillalovos requested a review from nejch June 9, 2021 23:16
Sometimes we have errors where we don't get a dictionary passed to
RESTObject.__init__() method. This breaks things but in confusing
ways.

Check in the __init__() method and raise an exception if it occurs.
@nejch nejch merged commit 600a2c1 into python-gitlab:master Jun 10, 2021
@JohnVillalovos JohnVillalovos deleted the jlvillal/check_attrs branch June 10, 2021 21:55
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

Successfully merging this pull request may close these issues.

3 participants