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 |
... | ... | |
46 | 46 |
|
47 | 47 |
print self.style.NOTICE("=== Creating schema ") \ |
48 | 48 |
+ self.style.SQL_TABLE(tenant.schema_name) |
49 |
tenant.create_schema(check_if_exists=True) |
|
49 |
with transaction.atomic(): |
|
50 |
tenant.create_schema(check_if_exists=True) |
|
50 | 51 |
except Exception as e: |
51 | 52 |
os.rmdir(tenant_dir_tmp) |
52 | 53 |
raise CommandError('tenant creation failed (%s)' % str(e)) |
53 |
- |