From b2b97d19b1b7b1a6577fe5975c9df6478badecdc Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 12 Apr 2018 11:10:21 +0200 Subject: [PATCH] multitenant: wrap schema creation in atomic() (#23119) --- hobo/multitenant/management/commands/create_tenant.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hobo/multitenant/management/commands/create_tenant.py b/hobo/multitenant/management/commands/create_tenant.py index d25f7f4..cda29fc 100644 --- a/hobo/multitenant/management/commands/create_tenant.py +++ b/hobo/multitenant/management/commands/create_tenant.py @@ -1,7 +1,7 @@ import os import sys -from django.db import connection +from django.db import connection, transaction from django.core.management.base import CommandError, BaseCommand from hobo.multitenant.middleware import TenantMiddleware, get_tenant_model @@ -47,7 +47,8 @@ class Command(BaseCommand): print print self.style.NOTICE("=== Creating schema ") \ + self.style.SQL_TABLE(tenant.schema_name) - tenant.create_schema(check_if_exists=True) + with transaction.atomic(): + tenant.create_schema(check_if_exists=True) except Exception as e: os.rmdir(tenant_dir_tmp) raise CommandError('tenant creation failed (%s)' % str(e)) -- 2.20.1