summaryrefslogtreecommitdiff
path: root/gitlab/objects.py
diff options
context:
space:
mode:
authorRichard Hansen <rhansen@rhansen.org>2016-01-23 03:57:12 -0500
committerRichard Hansen <rhansen@rhansen.org>2016-01-23 03:57:12 -0500
commitca6da62010ee88e1b03f7a5abbf69479103aa1e1 (patch)
treebc247c9e0f9662d9a53afd708ad36f67eb05b791 /gitlab/objects.py
parentc95b3c3b54c412cd5cc77c4d58816139363fb2d1 (diff)
downloadgitlab-ca6da62010ee88e1b03f7a5abbf69479103aa1e1.tar.gz
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
Diffstat (limited to 'gitlab/objects.py')
-rw-r--r--gitlab/objects.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/gitlab/objects.py b/gitlab/objects.py
index e1e62ce..9f3a655 100644
--- a/gitlab/objects.py
+++ b/gitlab/objects.py
@@ -33,7 +33,8 @@ class jsonEncoder(json.JSONEncoder):
def default(self, obj):
from gitlab import Gitlab
if isinstance(obj, GitlabObject):
- return obj.__dict__
+ return {k: v for k, v in obj.__dict__.iteritems()
+ if not isinstance(v, BaseManager)}
elif isinstance(obj, Gitlab):
return {'url': obj._url}
return json.JSONEncoder.default(self, obj)
@@ -475,7 +476,7 @@ class GitlabObject(object):
Returns:
str: The json string.
"""
- return json.dumps(self.__dict__, cls=jsonEncoder)
+ return json.dumps(self, cls=jsonEncoder)
class UserKey(GitlabObject):