Skip to content

Commit 79dc1f1

Browse files
author
Gauvain Pocentek
committed
Get rid of _sanitize_data
It was used in one class only, no need for added complexity.
1 parent 1940fee commit 79dc1f1

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

gitlab/mixins.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ def create(self, data, **kwargs):
200200
"""
201201
self._check_missing_create_attrs(data)
202202

203-
# special handling of the object if needed
204-
if hasattr(self, '_sanitize_data'):
205-
data = self._sanitize_data(data, 'create')
206-
207203
# We get the attributes that need some special transformation
208204
types = getattr(self, '_types', {})
209205

@@ -265,20 +261,14 @@ def update(self, id=None, new_data={}, **kwargs):
265261

266262
self._check_missing_update_attrs(new_data)
267263

268-
# special handling of the object if needed
269-
if hasattr(self, '_sanitize_data'):
270-
data = self._sanitize_data(new_data, 'update')
271-
else:
272-
data = new_data
273-
274264
# We get the attributes that need some special transformation
275265
types = getattr(self, '_types', {})
276266
for attr_name, type_cls in types.items():
277-
if attr_name in data.keys():
278-
type_obj = type_cls(data[attr_name])
279-
data[attr_name] = type_obj.get_for_api()
267+
if attr_name in new_data.keys():
268+
type_obj = type_cls(new_data[attr_name])
269+
new_data[attr_name] = type_obj.get_for_api()
280270

281-
return self.gitlab.http_put(path, post_data=data, **kwargs)
271+
return self.gitlab.http_put(path, post_data=new_data, **kwargs)
282272

283273

284274
class SetMixin(object):

gitlab/v4/objects.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,27 @@ class ApplicationSettingsManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
388388
'user_oauth_applications')
389389
)
390390

391-
def _sanitize_data(self, data, action):
392-
new_data = data.copy()
391+
@exc.on_http_error(exc.GitlabUpdateError)
392+
def update(self, id=None, new_data={}, **kwargs):
393+
"""Update an object on the server.
394+
395+
Args:
396+
id: ID of the object to update (can be None if not required)
397+
new_data: the update data for the object
398+
**kwargs: Extra options to send to the Gitlab server (e.g. sudo)
399+
400+
Returns:
401+
dict: The new object data (*not* a RESTObject)
402+
403+
Raises:
404+
GitlabAuthenticationError: If authentication is not correct
405+
GitlabUpdateError: If the server cannot perform the request
406+
"""
407+
408+
data = new_data.copy()
393409
if 'domain_whitelist' in data and data['domain_whitelist'] is None:
394-
new_data.pop('domain_whitelist')
395-
return new_data
410+
data.pop('domain_whitelist')
411+
super(ApplicationSettingsManager, self).update(id, data, **kwargs)
396412

397413

398414
class BroadcastMessage(SaveMixin, ObjectDeleteMixin, RESTObject):

0 commit comments

Comments
 (0)