Code

Ticket #18116: 18116-require-mysql-5.0.3-1.diff

File 18116-require-mysql-5.0.3-1.diff, 6.2 KB (added by ramiro, 2 years ago)
Line 
1diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
2--- a/django/db/backends/mysql/base.py
3+++ b/django/db/backends/mysql/base.py
4@@ -15,11 +15,13 @@
5     from django.core.exceptions import ImproperlyConfigured
6     raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
7 
8+from django.utils.functional import cached_property
9+
10 # We want version (1, 2, 1, 'final', 2) or later. We can't just use
11 # lexicographic ordering in this check because then (1, 2, 1, 'gamma')
12 # inadvertently passes the version test.
13 version = Database.version_info
14-if (version < (1,2,1) or (version[:3] == (1, 2, 1) and
15+if (version < (1, 2, 1) or (version[:3] == (1, 2, 1) and
16         (len(version) < 5 or version[3] != 'final' or version[4] < 2))):
17     from django.core.exceptions import ImproperlyConfigured
18     raise ImproperlyConfigured("MySQLdb-1.2.1p2 or newer is required; you have %s" % Database.__version__)
19@@ -163,6 +165,7 @@
20     supports_timezones = False
21     requires_explicit_null_ordering_when_grouping = True
22     allows_primary_key_0 = False
23+    uses_savepoints = True
24 
25     def __init__(self, connection):
26         super(DatabaseFeatures, self).__init__(connection)
27@@ -387,8 +390,6 @@
28             self.connection = Database.connect(**kwargs)
29             self.connection.encoders[SafeUnicode] = self.connection.encoders[unicode]
30             self.connection.encoders[SafeString] = self.connection.encoders[str]
31-            self.features.uses_savepoints = \
32-                self.get_server_version() >= (5, 0, 3)
33             connection_created.send(sender=self.__class__, connection=self)
34         cursor = self.connection.cursor()
35         if new_connection:
36@@ -405,10 +406,11 @@
37         except Database.NotSupportedError:
38             pass
39 
40-    def get_server_version(self):
41+    @cached_property
42+    def mysql_version(self):
43         if not self.server_version:
44             if not self._valid_connection():
45-                self.cursor()
46+                self.cursor().close()
47             m = server_version_re.match(self.connection.get_server_info())
48             if not m:
49                 raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info())
50diff --git a/django/db/backends/mysql/validation.py b/django/db/backends/mysql/validation.py
51--- a/django/db/backends/mysql/validation.py
52+++ b/django/db/backends/mysql/validation.py
53@@ -3,30 +3,18 @@
54 class DatabaseValidation(BaseDatabaseValidation):
55     def validate_field(self, errors, opts, f):
56         """
57-        There are some field length restrictions for MySQL:
58-
59-        - Prior to version 5.0.3, character fields could not exceed 255
60-          characters in length.
61-        - No character (varchar) fields can have a length exceeding 255
62-          characters if they have a unique index on them.
63+        MySQL has the following field length restriction:
64+        No character (varchar) fields can have a length exceeding 255
65+        characters if they have a unique index on them.
66         """
67         from django.db import models
68-        from MySQLdb import OperationalError
69-        try:
70-            db_version = self.connection.get_server_version()
71-            text_version = '.'.join([str(n) for n in db_version[:3]])
72-        except OperationalError:
73-            db_version = None
74-            text_version = ''
75         varchar_fields = (models.CharField, models.CommaSeparatedIntegerField,
76                 models.SlugField)
77         if isinstance(f, varchar_fields) and f.max_length > 255:
78-            if db_version and db_version < (5, 0, 3):
79-                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).'
80-            elif f.unique == True:
81+            if f.unique == True:
82                 msg = '"%(name)s": %(cls)s cannot have a "max_length" greater than 255 when using "unique=True".'
83             else:
84                 msg = None
85 
86             if msg:
87-                errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__, 'version': text_version})
88+                errors.add(opts, msg % {'name': f.name, 'cls': f.__class__.__name__})
89diff --git a/docs/ref/databases.txt b/docs/ref/databases.txt
90--- a/docs/ref/databases.txt
91+++ b/docs/ref/databases.txt
92@@ -122,30 +122,22 @@
93 MySQL notes
94 ===========
95 
96-Django expects the database to support transactions, referential integrity, and
97-Unicode (UTF-8 encoding). Fortunately, MySQL_ has all these features as
98-available as far back as 3.23. While it may be possible to use 3.23 or 4.0,
99-you'll probably have less trouble if you use 4.1 or 5.0.
100+Version support
101+---------------
102 
103-MySQL 4.1
104----------
105-
106-`MySQL 4.1`_ has greatly improved support for character sets. It is possible to
107-set different default character sets on the database, table, and column.
108-Previous versions have only a server-wide character set setting. It's also the
109-first version where the character set can be changed on the fly. 4.1 also has
110-support for views, but Django currently doesn't use views.
111-
112-MySQL 5.0
113----------
114+Django supports MySQL 5.0.3 and higher.
115 
116 `MySQL 5.0`_ adds the ``information_schema`` database, which contains detailed
117 data on all database schema. Django's ``inspectdb`` feature uses this
118-``information_schema`` if it's available. 5.0 also has support for stored
119-procedures, but Django currently doesn't use stored procedures.
120+``information_schema`` if it's available.
121+
122+.. versionchanged:: 1.5
123+    The minimum version requirement of MySQL 5.0.3 was set in Django 1.5.
124+
125+Django expects the database to support transactions, referential integrity, and
126+Unicode (UTF-8 encoding).
127 
128 .. _MySQL: http://www.mysql.com/
129-.. _MySQL 4.1: http://dev.mysql.com/doc/refman/4.1/en/index.html
130 .. _MySQL 5.0: http://dev.mysql.com/doc/refman/5.0/en/index.html
131 
132 Storage engines
133@@ -381,10 +373,6 @@
134 :class:`~django.db.models.SlugField` and
135 :class:`~django.db.models.CommaSeparatedIntegerField`.
136 
137-Furthermore, if you are using a version of MySQL prior to 5.0.3, all of those
138-column types have a maximum length restriction of 255 characters, regardless
139-of whether ``unique=True`` is specified or not.
140-
141 DateTime fields
142 ~~~~~~~~~~~~~~~
143