Fixed mutation erasing tags and description when other fields are modified

This commit is contained in:
Eliot Berriot 2020-03-26 16:36:03 +01:00
parent 3e902bd89e
commit f361791c1b
No known key found for this signature in database
GPG key ID: 6B501DFD73514E14
2 changed files with 45 additions and 4 deletions

View file

@ -9,6 +9,8 @@ from funkwhale_api.tags import serializers as tags_serializers
from . import models
NOOP = object()
def can_suggest(obj, actor):
return obj.is_local
@ -34,9 +36,10 @@ class TagMutation(mutations.UpdateMutationSerializer):
return handlers
def update(self, instance, validated_data):
tags = validated_data.pop("tags", [])
tags = validated_data.pop("tags", NOOP)
r = super().update(instance, validated_data)
tags_models.set_tags(instance, *tags)
if tags != NOOP:
tags_models.set_tags(instance, *tags)
return r
@ -53,9 +56,10 @@ class DescriptionMutation(mutations.UpdateMutationSerializer):
return handlers
def update(self, instance, validated_data):
description = validated_data.pop("description", None)
description = validated_data.pop("description", NOOP)
r = super().update(instance, validated_data)
common_utils.attach_content(instance, "description", description)
if description != NOOP:
common_utils.attach_content(instance, "description", description)
return r