Skip to content

Commit 8224b40

Browse files
fix: checking if RESTManager._from_parent_attrs is set
Prior to commit 3727cbd RESTManager._from_parent_attrs did not exist unless it was explicitly set. But commit 3727cbd set it to a default value of {}. So the checks using hasattr() were no longer valid. Update the checks to check if RESTManager._from_parent_attrs has a value.
1 parent de73ea7 commit 8224b40

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

gitlab/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,12 @@ def _compute_path(self, path: Optional[str] = None) -> Optional[str]:
290290
path = self._path
291291
if path is None:
292292
return None
293-
if self._parent is None or not hasattr(self, "_from_parent_attrs"):
293+
if self._parent is None or not self._from_parent_attrs:
294294
return path
295295

296296
data = {
297297
self_attr: getattr(self._parent, parent_attr, None)
298-
for self_attr, parent_attr in self._from_parent_attrs.items() # type: ignore
298+
for self_attr, parent_attr in self._from_parent_attrs.items()
299299
}
300300
self._parent_attrs = data
301301
return path % data

gitlab/v4/cli.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def do_custom(self):
6969
# Get the object (lazy), then act
7070
if in_obj:
7171
data = {}
72-
if hasattr(self.mgr, "_from_parent_attrs"):
72+
if self.mgr._from_parent_attrs:
7373
for k in self.mgr._from_parent_attrs:
7474
data[k] = self.args[k]
7575
if gitlab.mixins.GetWithoutIdMixin not in inspect.getmro(self.cls):
@@ -138,13 +138,11 @@ def _populate_sub_parser_by_class(cls, sub_parser):
138138

139139
sub_parser_action = sub_parser.add_parser(action_name)
140140
sub_parser_action.add_argument("--sudo", required=False)
141-
if hasattr(mgr_cls, "_from_parent_attrs"):
142-
[
141+
if mgr_cls._from_parent_attrs:
142+
for x in mgr_cls._from_parent_attrs:
143143
sub_parser_action.add_argument(
144144
"--%s" % x.replace("_", "-"), required=True
145145
)
146-
for x in mgr_cls._from_parent_attrs
147-
]
148146

149147
if action_name == "list":
150148
if hasattr(mgr_cls, "_list_filters"):
@@ -221,13 +219,11 @@ def _populate_sub_parser_by_class(cls, sub_parser):
221219
for action_name in cli.custom_actions[name]:
222220
sub_parser_action = sub_parser.add_parser(action_name)
223221
# Get the attributes for URL/path construction
224-
if hasattr(mgr_cls, "_from_parent_attrs"):
225-
[
222+
if mgr_cls._from_parent_attrs:
223+
for x in mgr_cls._from_parent_attrs:
226224
sub_parser_action.add_argument(
227225
"--%s" % x.replace("_", "-"), required=True
228226
)
229-
for x in mgr_cls._from_parent_attrs
230-
]
231227
sub_parser_action.add_argument("--sudo", required=False)
232228

233229
# We need to get the object somehow
@@ -256,13 +252,11 @@ def _populate_sub_parser_by_class(cls, sub_parser):
256252
name = mgr_cls.__name__
257253
for action_name in cli.custom_actions[name]:
258254
sub_parser_action = sub_parser.add_parser(action_name)
259-
if hasattr(mgr_cls, "_from_parent_attrs"):
260-
[
255+
if mgr_cls._from_parent_attrs:
256+
for x in mgr_cls._from_parent_attrs:
261257
sub_parser_action.add_argument(
262258
"--%s" % x.replace("_", "-"), required=True
263259
)
264-
for x in mgr_cls._from_parent_attrs
265-
]
266260
sub_parser_action.add_argument("--sudo", required=False)
267261

268262
required, optional, dummy = cli.custom_actions[name][action_name]

0 commit comments

Comments
 (0)