Skip to content

Commit 67f9537

Browse files
author
Philipp Busch
committed
Convert response list to single data source for iid requests
1 parent 5f444e4 commit 67f9537

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

gitlab/objects.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,22 @@ def __init__(self, gl, data=None, **kwargs):
377377
data = self.gitlab.get(self.__class__, data, **kwargs)
378378
self._from_api = True
379379

380+
# the API returned a list because custom kwargs where used
381+
# instead of the id to request an object. Usually parameters
382+
# other than an id return ambiguous results. However in the
383+
# gitlab universe iids together with a project_id are
384+
# unambiguous for merge requests and issues, too.
385+
# So if there is only one element we can use it as our data
386+
# source.
387+
if 'iid' in kwargs and isinstance(data, list):
388+
if len(data) < 1:
389+
raise GitlabGetError('Not found')
390+
elif len(data) == 1:
391+
data = data[0]
392+
else:
393+
raise GitlabGetError('Impossible! You found multiple'
394+
' elements with the same iid.')
395+
380396
self._set_from_dict(data)
381397

382398
if kwargs:

0 commit comments

Comments
 (0)