From c95b3c3b54c412cd5cc77c4d58816139363fb2d1 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sat, 23 Jan 2016 03:56:55 -0500 Subject: add a missing import statement Add the import inside the function rather than at the top of the file because otherwise it would introduce a circular dependency. --- gitlab/objects.py | 1 + 1 file changed, 1 insertion(+) (limited to 'gitlab/objects.py') diff --git a/gitlab/objects.py b/gitlab/objects.py index d0e05ea..e1e62ce 100644 --- a/gitlab/objects.py +++ b/gitlab/objects.py @@ -31,6 +31,7 @@ from gitlab.exceptions import * # noqa class jsonEncoder(json.JSONEncoder): def default(self, obj): + from gitlab import Gitlab if isinstance(obj, GitlabObject): return obj.__dict__ elif isinstance(obj, Gitlab): -- cgit v1.2.1 From ca6da62010ee88e1b03f7a5abbf69479103aa1e1 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sat, 23 Jan 2016 03:57:12 -0500 Subject: skip BaseManager attributes when encoding to JSON This fixes the following exception when calling User.json(): TypeError: is not JSON serializable --- gitlab/objects.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'gitlab/objects.py') 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): -- cgit v1.2.1