Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 4b3fd424f46d6a6491dd549783b37401dcba89f5 1 parent 60ceeda
@claudep claudep authored
Showing with 9 additions and 3 deletions.
  1. +9 −3 django/db/backends/mysql/validation.py
View
12 django/db/backends/mysql/validation.py
@@ -11,11 +11,17 @@ def validate_field(self, errors, opts, f):
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 @@ def validate_field(self, errors, opts, f):
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})
Please sign in to comment.
Something went wrong with that request. Please try again.