8000 Merge pull request #169 from hakkeroid/allow-iid-parameter-to-request… · DavidGarfinkle/python-gitlab@20fdbe8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 20fdbe8

Browse files
author
Gauvain Pocentek
authored
Merge pull request python-gitlab#169 from hakkeroid/allow-iid-parameter-to-request-distinct-objects
Convert response list to single data source for iid requests
2 parents 9da5d69 + 23b5b6e commit 20fdbe8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

gitlab/objects.py

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

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

383399
if kwargs:

0 commit comments

Comments
 (0)
0