Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Claude Paroz authored April 02, 2012

Showing 1 changed file with 9 additions and 3 deletions. Show diff stats Hide diff stats

  1. 12  django/db/backends/mysql/validation.py
12  django/db/backends/mysql/validation.py
@@ -11,11 +11,17 @@ def validate_field(self, errors, opts, f):
11 11
           characters if they have a unique index on them.
12 12
         """
13 13
         from django.db import models
14  
-        db_version = self.connection.get_server_version()
  14
+        from MySQLdb import OperationalError
  15
+        try:
  16
+            db_version = self.connection.get_server_version()
  17
+            text_version = '.'.join([str(n) for n in db_version[:3]])
  18
+        except OperationalError:
  19
+            db_version = None
  20
+            text_version = ''
15 21
         varchar_fields = (models.CharField, models.CommaSeparatedIntegerField,
16 22
                 models.SlugField)
17 23
         if isinstance(f, varchar_fields) and f.max_length > 255:
18  
-            if db_version < (5, 0, 3):
  24
+            if db_version and db_version < (5, 0, 3):
19 25
                 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).'
20 26
             elif f.unique == True:
21 27
                 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):
23 29
                 msg = None
24 30
 
25 31
             if msg:
26  
-                errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__, 'version': '.'.join([str(n) for n in db_version[:3]])})
  32
+                errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__, 'version': text_version})

0 notes on commit 4b3fd42

Please sign in to comment.
Something went wrong with that request. Please try again.