Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc7bcc25

Browse files
fix: catch invalid type used to initialize RESTObject
Sometimes we have errors where we don't get a dictionary passed toRESTObject.__init__() method. This breaks things but in confusingways.Check in the __init__() method and raise an exception if it occurs.
1 parent161bb0b commitc7bcc25

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

‎gitlab/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
fromtypingimportAny,Dict,Iterable,NamedTuple,Optional,Tuple,Type
2121

2222
fromgitlabimporttypesasg_types
23+
fromgitlab.exceptionsimportGitlabParsingError
2324

2425
from .clientimportGitlab,GitlabList
2526

@@ -51,6 +52,12 @@ class RESTObject(object):
5152
manager:"RESTManager"
5253

5354
def__init__(self,manager:"RESTManager",attrs:Dict[str,Any])->None:
55+
ifnotisinstance(attrs,dict):
56+
raiseGitlabParsingError(
57+
"Attempted to initialize RESTObject with a non-dictionary value: "
58+
"{!r}\nThis likely indicates an incorrect or malformed server "
59+
"response.".format(attrs)
60+
)
5461
self.__dict__.update(
5562
{
5663
"manager":manager,

‎tests/unit/test_base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
importpytest
2121

22+
importgitlab
2223
fromgitlabimportbase
2324

2425

@@ -85,6 +86,10 @@ def test_instantiate(self, fake_gitlab, fake_manager):
8586
assertfake_manager==obj.manager
8687
assertfake_gitlab==obj.manager.gitlab
8788

89+
deftest_instantiate_non_dict(self,fake_gitlab,fake_manager):
90+
withpytest.raises(gitlab.exceptions.GitlabParsingError):
91+
FakeObject(fake_manager, ["a","list","fails"])
92+
8893
deftest_picklability(self,fake_manager):
8994
obj=FakeObject(fake_manager, {"foo":"bar"})
9095
original_obj_module=obj._module

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp