summaryrefslogtreecommitdiff
path: root/gitlab/base.py
diff options
context:
space:
mode:
authorLyudmil Nenov <lyudmil.nenov@gmail.com>2017-11-03 16:05:17 +0200
committerGauvain Pocentek <gauvain@pocentek.net>2017-11-03 15:05:17 +0100
commit226e6ce9e5217367c896125a2b4b9d16afd2cf94 (patch)
treea02b5fe4e9f235be3c2b9b128f931a99da03a0bc /gitlab/base.py
parent38d446737f45ea54136d1f03f75fbddf46c45e00 (diff)
downloadgitlab-226e6ce9e5217367c896125a2b4b9d16afd2cf94.tar.gz
Module's base objects serialization (#359)
Make gitlab objects serializable With current implementation of API v3 and v4 support, some instances have properties of type module and are not serializable. Handle these properties manually with setstate and getstate methods.
Diffstat (limited to 'gitlab/base.py')
-rw-r--r--gitlab/base.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/gitlab/base.py b/gitlab/base.py
index 4213d2f..ec5f698 100644
--- a/gitlab/base.py
+++ b/gitlab/base.py
@@ -416,6 +416,17 @@ class GitlabObject(object):
if not hasattr(self, "id"):
self.id = None
+ def __getstate__(self):
+ state = self.__dict__.copy()
+ module = state.pop('_module')
+ state['_module_name'] = module.__name__
+ return state
+
+ def __setstate__(self, state):
+ module_name = state.pop('_module_name')
+ self.__dict__.update(state)
+ self._module = importlib.import_module(module_name)
+
def _set_manager(self, var, cls, attrs):
manager = cls(self.gitlab, self, attrs)
setattr(self, var, manager)
@@ -555,6 +566,17 @@ class RESTObject(object):
self.__dict__['_parent_attrs'] = self.manager.parent_attrs
self._create_managers()
+ def __getstate__(self):
+ state = self.__dict__.copy()
+ module = state.pop('_module')
+ state['_module_name'] = module.__name__
+ return state
+
+ def __setstate__(self, state):
+ module_name = state.pop('_module_name')
+ self.__dict__.update(state)
+ self._module = importlib.import_module(module_name)
+
def __getattr__(self, name):
try:
return self.__dict__['_updated_attrs'][name]