Ticket #17300: 17300-2.diff

File 17300-2.diff, 3.0 KB (added by Claude Paroz, 13 years ago)

Same patch with mysql returning utils.DatabaseError

  • django/core/management/commands/createcachetable.py

    diff --git a/django/core/management/commands/createcachetable.py b/django/core/management/commands/createcachetable.py
    index 287a036..47dabf7 100644
    a b from optparse import make_option  
    33from django.core.cache.backends.db import BaseDatabaseCache
    44from django.core.management.base import LabelCommand
    55from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS
     6from django.db.utils import DatabaseError
    67
    78class Command(LabelCommand):
    89    help = "Creates the table needed to use the SQL cache backend."
    class Command(LabelCommand):  
    5152            full_statement.append('    %s%s' % (line, i < len(table_output)-1 and ',' or ''))
    5253        full_statement.append(');')
    5354        curs = connection.cursor()
    54         curs.execute("\n".join(full_statement))
    55         for statement in index_output:
    56             curs.execute(statement)
    57         transaction.commit_unless_managed(using=db)
     55        try:
     56            curs.execute("\n".join(full_statement))
     57            for statement in index_output:
     58                curs.execute(statement)
     59            transaction.commit_unless_managed(using=db)
     60        except DatabaseError, e:
     61            self.stderr.write(
     62                self.style.ERROR("Cache database '%s' could not be created.\nThe error was: %s.\n" %
     63                    (tablename, e)))
     64            transaction.rollback_unless_managed(using=db)
  • django/db/backends/mysql/base.py

    diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
    index 93aaf99..b8c8ffe 100644
    a b class CursorWrapper(object):  
    105105            # misclassified and Django would prefer the more logical place.
    106106            if e[0] in self.codes_for_integrityerror:
    107107                raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
    108             raise
     108            raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
    109109        except Database.DatabaseError, e:
    110110            raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
    111111
  • tests/regressiontests/cache/tests.py

    diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
    index c5dc457..eabbfac 100644
    a b class DBCacheTests(BaseCacheTests, TransactionTestCase):  
    776776        self.cache = get_cache('db://%s?max_entries=30&cull_frequency=0' % self._table_name)
    777777        self.perform_cull_test(50, 18)
    778778
     779    def test_second_call_dont_crash(self):
     780        from StringIO import StringIO
     781        out = StringIO()
     782        management.call_command('createcachetable', self._table_name, verbosity=0, interactive=False, stderr=out)
     783        self.assertTrue("Cache database 'test cache table' could not be created" in out.getvalue())
     784
    779785
    780786DBCacheWithTimeZoneTests = override_settings(USE_TZ=True)(DBCacheTests)
    781787
Back to Top