Skip to content

fix: catch invalid type used to initialize RESTObject - #1487

Merged
nejch merged 1 commit into
python-gitlab:masterfrom
JohnVillalovos:jlvillal/check_attrs
Jun 10, 2021
Merged

fix: catch invalid type used to initialize RESTObject#1487
nejch merged 1 commit into
python-gitlab:masterfrom
JohnVillalovos:jlvillal/check_attrs

Conversation

@JohnVillalovos

@JohnVillalovos JohnVillalovos commented May 31, 2021

Copy link
Copy Markdown
Member
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
Copy Markdown
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

codecov-commenter commented May 31, 2021

Copy link
Copy Markdown

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

nejch commented Jun 1, 2021

Copy link
Copy Markdown
Member

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

JohnVillalovos commented Jun 1, 2021

Copy link
Copy Markdown
Member Author

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

@nejch nejch left a comment

Copy link
Copy Markdown
Member

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.

Comment thread gitlab/base.py
Comment thread gitlab/base.py Outdated
@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