1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Used CommandError in createcachetable command.

Raising CommandError whenever a management command meets an error
condition is the standard way to handle errors in commands.
This commit is contained in:
Claude Paroz
2012-05-27 23:03:21 +02:00
parent f2b6763ad7
commit cc4b4d9fd3
2 changed files with 14 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
from optparse import make_option
from django.core.cache.backends.db import BaseDatabaseCache
from django.core.management.base import LabelCommand
from django.core.management.base import LabelCommand, CommandError
from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS
from django.db.utils import DatabaseError
@@ -55,11 +55,10 @@ class Command(LabelCommand):
try:
curs.execute("\n".join(full_statement))
except DatabaseError as e:
self.stderr.write(
transaction.rollback_unless_managed(using=db)
raise CommandError(
"Cache table '%s' could not be created.\nThe error was: %s." %
(tablename, e))
transaction.rollback_unless_managed(using=db)
else:
for statement in index_output:
curs.execute(statement)
transaction.commit_unless_managed(using=db)
for statement in index_output:
curs.execute(statement)
transaction.commit_unless_managed(using=db)