diff --git a/pillarsdk/nodes.py b/pillarsdk/nodes.py index 6902ee9..735a80e 100755 --- a/pillarsdk/nodes.py +++ b/pillarsdk/nodes.py @@ -54,6 +54,17 @@ class Node(List, Find, Create, Post, Update, Delete, Replace): raise ResourceNotFound(response) def update(self, attributes=None, api=None): + def pop_none_attributes(attributes): + """Return a new dict with all None values removed""" + out = {} + for k, v in attributes.iteritems(): + if v: + if type(v) is dict: + attributes[k] = pop_none_attributes(v) + else: + out[k] = v + return out + api = api or self.api attributes = attributes or self.to_dict() etag = attributes['_etag'] @@ -63,9 +74,11 @@ class Node(List, Find, Create, Post, Update, Delete, Replace): attributes.pop('_updated') attributes.pop('_links', None) attributes.pop('allowed_methods') - for attr in ['parent', 'picture']: - if attr in attributes and attributes[attr] is None: - attributes.pop(attr, None) + # for attr in ['parent', 'picture']: + # if attr in attributes and attributes[attr] is None: + # attributes.pop(attr, None) + pop_none_attributes(attributes) + url = utils.join_url(self.path, str(self['_id'])) headers = utils.merge_dict( self.http_headers(),