diff --git a/djangoldp/serializers.py b/djangoldp/serializers.py index e45a55a7559534c0ed8131f74cbccd49f7ecb527..eb6170b6cbc1f2f2514b9ef45e2dd2188895f742 100644 --- a/djangoldp/serializers.py +++ b/djangoldp/serializers.py @@ -8,6 +8,7 @@ from django.conf import settings from django.contrib.auth import get_user_model from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ValidationError as DjangoValidationError +from django.db import transaction from django.urls import resolve, Resolver404, get_script_prefix from django.urls.resolvers import get_resolver from django.db.models import QuerySet @@ -588,9 +589,9 @@ class LDPSerializer(HyperlinkedModelSerializer): return super().get_value(dictionary) def create(self, validated_data): - instance = self.internal_create(validated_data, model=self.Meta.model) - - self.attach_related_object(instance, validated_data) + with transaction.atomic(): + instance = self.internal_create(validated_data, model=self.Meta.model) + self.attach_related_object(instance, validated_data) return instance