@@ -209,7 +209,8 @@ class GitlabObject(object):
209209 #: Attribute to use as ID when displaying the object.
210210 shortPrintAttr = None
211211
212- def _data_for_gitlab (self , extra_parameters = {}, update = False ):
212+ def _data_for_gitlab (self , extra_parameters = {}, update = False ,
213+ as_json = True ):
213214 data = {}
214215 if update and (self .requiredUpdateAttrs or self .optionalUpdateAttrs ):
215216 attributes = itertools .chain (self .requiredUpdateAttrs ,
@@ -227,7 +228,7 @@ def _data_for_gitlab(self, extra_parameters={}, update=False):
227228
228229 data .update (extra_parameters )
229230
230- return json .dumps (data )
231+ return json .dumps (data ) if as_json else data
231232
232233 @classmethod
233234 def list (cls , gl , ** kwargs ):
@@ -573,7 +574,8 @@ class User(GitlabObject):
573574 ('keys' , UserKeyManager , [('user_id' , 'id' )])
574575 ]
575576
576- def _data_for_gitlab (self , extra_parameters = {}, update = False ):
577+ def _data_for_gitlab (self , extra_parameters = {}, update = False ,
578+ as_json = True ):
577579 if hasattr (self , 'confirm' ):
578580 self .confirm = str (self .confirm ).lower ()
579581 return super (User , self )._data_for_gitlab (extra_parameters )
@@ -1191,7 +1193,8 @@ class ProjectIssue(GitlabObject):
11911193 managers = [('notes' , ProjectIssueNoteManager ,
11921194 [('project_id' , 'project_id' ), ('issue_id' , 'id' )])]
11931195
1194- def _data_for_gitlab (self , extra_parameters = {}, update = False ):
1196+ def _data_for_gitlab (self , extra_parameters = {}, update = False ,
1197+ as_json = True ):
11951198 # Gitlab-api returns labels in a json list and takes them in a
11961199 # comma separated list.
11971200 if hasattr (self , "labels" ):
@@ -1369,18 +1372,16 @@ class ProjectMergeRequest(GitlabObject):
13691372 managers = [('notes' , ProjectMergeRequestNoteManager ,
13701373 [('project_id' , 'project_id' ), ('merge_request_id' , 'id' )])]
13711374
1372- def _data_for_gitlab (self , extra_parameters = {}, update = False ):
1375+ def _data_for_gitlab (self , extra_parameters = {}, update = False ,
1376+ as_json = True ):
13731377 data = (super (ProjectMergeRequest , self )
1374- ._data_for_gitlab (extra_parameters , update = update ))
1378+ ._data_for_gitlab (extra_parameters , update = update ,
1379+ as_json = False ))
13751380 if update :
13761381 # Drop source_branch attribute as it is not accepted by the gitlab
13771382 # server (Issue #76)
1378- # We need to unserialize and reserialize the
1379- # data, this is far from optimal
1380- d = json .loads (data )
1381- d .pop ('source_branch' , None )
1382- data = json .dumps (d )
1383- return data
1383+ data .pop ('source_branch' , None )
1384+ return json .dumps (data )
13841385
13851386 def subscribe (self , ** kwargs ):
13861387 """Subscribe to a MR.
0 commit comments