diff options
| author | Claude Paroz <claude@2xlibre.net> | 2012-04-02 20:29:50 +0000 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-04-02 20:29:50 +0000 |
| commit | 4b3fd424f46d6a6491dd549783b37401dcba89f5 (patch) | |
| tree | 4c8de4f8d4e98e712c8a0315c8b2d8242720b4e6 | |
| parent | 60ceeda9d5a1dc2f62b605db5627e1da55a13911 (diff) | |
Fixed #15782 -- Prevented MySQL backend to crash on runserver when db server is down. Thanks toofishes for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17868 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/db/backends/mysql/validation.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/django/db/backends/mysql/validation.py b/django/db/backends/mysql/validation.py index 197f91310e..663cc7da4e 100644 --- a/django/db/backends/mysql/validation.py +++ b/django/db/backends/mysql/validation.py @@ -11,11 +11,17 @@ class DatabaseValidation(BaseDatabaseValidation): characters if they have a unique index on them. """ from django.db import models - db_version = self.connection.get_server_version() + from MySQLdb import OperationalError + try: + db_version = self.connection.get_server_version() + text_version = '.'.join([str(n) for n in db_version[:3]]) + except OperationalError: + db_version = None + text_version = '' varchar_fields = (models.CharField, models.CommaSeparatedIntegerField, models.SlugField) if isinstance(f, varchar_fields) and f.max_length > 255: - if db_version < (5, 0, 3): + if db_version and db_version < (5, 0, 3): msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when you are using a version of MySQL prior to 5.0.3 (you are using %(version)s).' elif f.unique == True: msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".' @@ -23,4 +29,4 @@ class DatabaseValidation(BaseDatabaseValidation): msg = None if msg: - errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__, 'version': '.'.join([str(n) for n in db_version[:3]])}) + errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__, 'version': text_version}) |
