Skip to content

Commit ca6da62

Browse files
committed
skip BaseManager attributes when encoding to JSON
This fixes the following exception when calling User.json(): TypeError: <gitlab.objects.UserKeyManager object at 0x7f0477391ed0> is not JSON serializable
1 parent c95b3c3 commit ca6da62

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

gitlab/objects.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class jsonEncoder(json.JSONEncoder):
3333
def default(self, obj):
3434
from gitlab import Gitlab
3535
if isinstance(obj, GitlabObject):
36-
return obj.__dict__
36+
return {k: v for k, v in obj.__dict__.iteritems()
37+
if not isinstance(v, BaseManager)}
3738
elif isinstance(obj, Gitlab):
3839
return {'url': obj._url}
3940
return json.JSONEncoder.default(self, obj)
@@ -475,7 +476,7 @@ def json(self):
475476
Returns:
476477
str: The json string.
477478
"""
478-
return json.dumps(self.__dict__, cls=jsonEncoder)
479+
return json.dumps(self, cls=jsonEncoder)
479480

480481

481482
class UserKey(GitlabObject):

0 commit comments

Comments
 (0)