From da6dec5a610620b1b3e1398cfb957bbae710aae1 Mon Sep 17 00:00:00 2001 From: Marc 'risson' Schmitt Date: Thu, 11 Jan 2024 14:46:53 +0100 Subject: [PATCH] try running tenant save in a transaction Signed-off-by: Marc 'risson' Schmitt --- authentik/tenants/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/authentik/tenants/models.py b/authentik/tenants/models.py index 603cd22f3..a4cff57ce 100644 --- a/authentik/tenants/models.py +++ b/authentik/tenants/models.py @@ -4,7 +4,7 @@ from uuid import uuid4 from django.apps import apps 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.dispatch import receiver from django.utils.translation import gettext_lazy as _ @@ -84,7 +84,8 @@ class Tenant(TenantMixin, SerializerModel): def save(self, *args, **kwargs): if self.schema_name == "template": raise IntegrityError("Cannot create schema named template") - super().save(*args, **kwargs) + with transaction.atomic(): + super().save(*args, **kwargs) def delete(self, *args, **kwargs): if self.schema_name in ("public", "template"):