0001-multitenant-wrap-schema-creation-in-atomic-23119.patch
hobo/multitenant/management/commands/create_tenant.py | ||
---|---|---|
1 | 1 |
import os |
2 | 2 |
import sys |
3 | 3 | |
4 |
from django.db import connection |
|
4 |
from django.db import connection, transaction
|
|
5 | 5 |
from django.core.management.base import CommandError, BaseCommand |
6 | 6 | |
7 | 7 |
from hobo.multitenant.middleware import TenantMiddleware, get_tenant_model |
... | ... | |
47 | 47 |
|
48 | 48 |
print self.style.NOTICE("=== Creating schema ") \ |
49 | 49 |
+ self.style.SQL_TABLE(tenant.schema_name) |
50 |
tenant.create_schema(check_if_exists=True) |
|
50 |
with transaction.atomic(): |
|
51 |
tenant.create_schema(check_if_exists=True) |
|
51 | 52 |
except Exception as e: |
52 | 53 |
os.rmdir(tenant_dir_tmp) |
53 | 54 |
raise CommandError('tenant creation failed (%s)' % str(e)) |
54 |
- |