try running tenant save in a transaction

Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
Marc 'risson' Schmitt 2024-01-11 14:46:53 +01:00
parent 6a11b24896
commit da6dec5a61
No known key found for this signature in database
GPG Key ID: 9C3FA22FABF1AA8D
1 changed files with 3 additions and 2 deletions

View File

@ -4,7 +4,7 @@ from uuid import uuid4
from django.apps import apps from django.apps import apps
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.db import models from django.db import models, transaction
from django.db.utils import IntegrityError from django.db.utils import IntegrityError
from django.dispatch import receiver from django.dispatch import receiver
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
@ -84,6 +84,7 @@ class Tenant(TenantMixin, SerializerModel):
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if self.schema_name == "template": if self.schema_name == "template":
raise IntegrityError("Cannot create schema named template") raise IntegrityError("Cannot create schema named template")
with transaction.atomic():
super().save(*args, **kwargs) super().save(*args, **kwargs)
def delete(self, *args, **kwargs): def delete(self, *args, **kwargs):