Skip to content

Commit

Permalink
feat: add support for lists of integers to ListAttribute
Browse files Browse the repository at this point in the history
Previously ListAttribute only support lists of integers. Now be more
flexible and support lists of items which can be coerced into strings,
for example integers.

This will help us fix issue #1407 by using ListAttribute for the
'iids' field.
  • Loading branch information
JohnVillalovos committed Apr 25, 2021
1 parent e37de18 commit 115938b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions gitlab/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def test_list_attribute_get_for_api_from_list():
assert o.get_for_api() == "foo,bar,baz"


def test_list_attribute_get_for_api_from_int_list():
o = types.ListAttribute([1, 9, 7])
assert o.get_for_api() == "1,9,7"


def test_list_attribute_does_not_split_string():
o = types.ListAttribute("foo")
assert o.get_for_api() == "foo"
Expand Down
2 changes: 1 addition & 1 deletion gitlab/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_for_api(self):
if isinstance(self._value, str):
return self._value

return ",".join(self._value)
return ",".join([str(x) for x in self._value])


class LowercaseStringAttribute(GitlabAttribute):
Expand Down

0 comments on commit 115938b

Please sign in to comment.