Skip to content

Commit d4803f9

Browse files
author
Gauvain Pocentek
committed
Fix handling of boolean values
Gitlab expects an int (1 or 0) as value for boolean attributes. Transform python bool's into int's when creating or updating objects. Closes #22
1 parent 34d6952 commit d4803f9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

gitlab.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ def create(self, obj):
281281
url = obj._url % args
282282
url = '%s%s' % (self._url, url)
283283

284+
for k, v in obj.__dict__.items():
285+
if type(v) == bool:
286+
obj.__dict__[k] = 1 if v else 0
287+
284288
try:
285289
r = requests.post(url, obj.__dict__,
286290
headers=self.headers,
@@ -304,8 +308,10 @@ def update(self, obj):
304308
# build a dict of data that can really be sent to server
305309
d = {}
306310
for k, v in obj.__dict__.items():
307-
if type(v) in (int, str, bool):
311+
if type(v) in (int, str):
308312
d[k] = str(v)
313+
elif type(v) == bool:
314+
d[k] = 1 if v else 0
309315
elif type(v) == unicode:
310316
d[k] = str(v.encode(self.gitlab_encoding, "replace"))
311317

0 commit comments

Comments
 (0)