From 5bce4d9932960e45b9ebefff94cfc1553e63761f Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 15 Oct 2020 15:00:20 +0300 Subject: [PATCH] Collection Type: fix backwards compatibility for creating new collections. Continuation to 409248d419aa0fbbc23fad4ec163c95fb59ebad5. --- django_etebase/serializers.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/django_etebase/serializers.py b/django_etebase/serializers.py index d753bf9..038e879 100644 --- a/django_etebase/serializers.py +++ b/django_etebase/serializers.py @@ -293,7 +293,8 @@ class CollectionSerializer(BetterErrorsMixin, serializers.ModelSerializer): def create(self, validated_data): """Function that's called when this serializer creates an item""" collection_key = validated_data.pop('collectionKey') - collection_type = validated_data.pop('collectionType') + # FIXME: remove the None fallback once "collection-type-migration" is done + collection_type = validated_data.pop('collectionType', None) main_item_data = validated_data.pop('main_item') etag = main_item_data.pop('etag') @@ -317,7 +318,11 @@ class CollectionSerializer(BetterErrorsMixin, serializers.ModelSerializer): user = validated_data.get('owner') - collection_type_obj, _ = models.CollectionType.objects.get_or_create(uid=collection_type, owner=user) + # FIXME: remove the if statement (and else branch) once "collection-type-migration" is done + if collection_type is not None: + collection_type_obj, _ = models.CollectionType.objects.get_or_create(uid=collection_type, owner=user) + else: + collection_type_obj = None models.CollectionMember(collection=instance, stoken=models.Stoken.objects.create(),