Skip to content

Commit

Permalink
Merge pull request #169 from hakkeroid/allow-iid-parameter-to-request…
Browse files Browse the repository at this point in the history
…-distinct-objects

Convert response list to single data source for iid requests
  • Loading branch information
Gauvain Pocentek committed Oct 23, 2016
2 parents 9da5d69 + 23b5b6e commit 20fdbe8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions gitlab/objects.py
Expand Up @@ -378,6 +378,22 @@ def __init__(self, gl, data=None, **kwargs):
data = self.gitlab.get(self.__class__, data, **kwargs)
self._from_api = True

# the API returned a list because custom kwargs where used
# instead of the id to request an object. Usually parameters
# other than an id return ambiguous results. However in the
# gitlab universe iids together with a project_id are
# unambiguous for merge requests and issues, too.
# So if there is only one element we can use it as our data
# source.
if 'iid' in kwargs and isinstance(data, list):
if len(data) < 1:
raise GitlabGetError('Not found')
elif len(data) == 1:
data = data[0]
else:
raise GitlabGetError('Impossible! You found multiple'
' elements with the same iid.')

self._set_from_dict(data, **kwargs)

if kwargs:
Expand Down

0 comments on commit 20fdbe8

Please sign in to comment.