API: Make all mutating endpoints transactional (#6430)

All of our API endpoints that do something in the system do at least two
SQL queries, one for the actual change and one for the log entry. Often
many more. We want all of this to happen in a transaction so we know an
API call was executed or not at all, not half-way.
This commit is contained in:
Raphael Michel
2026-08-05 16:52:28 +02:00
committed by GitHub
parent e3fa1aed7f
commit 5c448279f0
9 changed files with 67 additions and 0 deletions
+4
View File
@@ -20,6 +20,7 @@
# <https://www.gnu.org/licenses/>.
#
from django.core.exceptions import ValidationError
from django.db import transaction
from django_filters.rest_framework import DjangoFilterBackend, FilterSet
from django_scopes import scopes_disabled
from rest_framework import viewsets
@@ -118,6 +119,7 @@ class RuleViewSet(viewsets.ModelViewSet):
def get_queryset(self):
return Rule.objects.filter(event=self.request.event)
@transaction.atomic()
def perform_create(self, serializer):
super().perform_create(serializer)
serializer.instance.log_action(
@@ -128,6 +130,7 @@ class RuleViewSet(viewsets.ModelViewSet):
)
@transaction.atomic()
def perform_update(self, serializer):
super().perform_update(serializer)
serializer.instance.log_action(
@@ -137,6 +140,7 @@ class RuleViewSet(viewsets.ModelViewSet):
data=self.request.data
)
@transaction.atomic()
def perform_destroy(self, instance):
instance.log_action(
'pretix.plugins.sendmail.rule.deleted',