From cd86c060b5242d82a3b2a62b0ad93bd5f42eb1c5 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 15 Dec 2020 10:14:15 +0200 Subject: [PATCH] Collection: fix UID validation to return a Conflict error. --- 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 9628986..223e48f 100644 --- a/django_etebase/serializers.py +++ b/django_etebase/serializers.py @@ -323,12 +323,17 @@ class CollectionSerializer(BetterErrorsMixin, serializers.ModelSerializer): if etag is not None: raise EtebaseValidationError("bad_etag", "etag is not null") + try: + instance.validate_unique() + except django_exceptions.ValidationError: + raise EtebaseValidationError( + "unique_uid", "Collection with this uid already exists", status_code=status.HTTP_409_CONFLICT + ) instance.save() + main_item = models.CollectionItem.objects.create(**main_item_data, collection=instance) instance.main_item = main_item - - instance.full_clean() instance.save() process_revisions_for_item(main_item, revision_data)