Skip to content

bugfix: Serializer.create completed in a transaction

Calum Mackervoy requested to merge transaction-create into master

This code ensures that if attach_related_object fails, the whole of the create request fails

Tested with @fabien4vo and it resolves the issue with DjangoLDP-Polls (with his signal receiver code)

@balessan I changed my mind and wrote a transaction-based solution because I believe that this code:

def create(self, validated_data):
    instance = self.internal_create(validated_data, model=self.Meta.model)
    
    raise Exception("kill me")

    self.attach_related_object(instance, validated_data)
    return instance

Should fail completely, rather than creating the base object but not the rest of the request

Merge request reports