]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Get MariaDB normalized version relative to "MariaDB" token
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 20 Oct 2017 20:07:49 +0000 (16:07 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 23 Oct 2017 22:51:53 +0000 (18:51 -0400)
Fixed regression from 1.2.0b3 where "MariaDB" version comparison can
fail for some particular MariaDB version strings under Python 3.

For 1.1, this was merged as part of #4097

Change-Id: Iedf49f40c1614ccedf63e0fa26719dd704da104d
Fixes: #4115
(cherry picked from commit 57f7788ec2ea0de56137c8ac6909948e2ae91489)

lib/sqlalchemy/dialects/mysql/base.py
test/dialect/mysql/test_dialect.py

index 70d4cdf106d0a557328b242336d3249f64d69545..0abbf6b4b7e16b2f06e053c875d2205ea8456f38 100644 (file)
@@ -1747,8 +1747,9 @@ class MySQLDialect(default.DefaultDialect):
 
     @property
     def _mariadb_normalized_version_info(self):
-        if len(self.server_version_info) > 5:
-            return self.server_version_info[3:]
+        if self._is_mariadb:
+            idx = self.server_version_info.index('MariaDB')
+            return self.server_version_info[idx - 3: idx]
         else:
             return self.server_version_info
 
index cf8641ddcd9c49e52b59dfa0c5531a67664a572b..328348a9c362a7eab571495645c5a26fde132c15 100644 (file)
@@ -8,6 +8,7 @@ from sqlalchemy import testing
 from sqlalchemy.testing import engines
 from ...engine import test_execute
 import datetime
+from sqlalchemy.dialects import mysql
 
 
 class DialectTest(fixtures.TestBase):
@@ -144,6 +145,45 @@ class DialectTest(fixtures.TestBase):
             assert c.execute('SELECT @@tx_isolation;').scalar() == mysql_value
 
 
+class ParseVersionTest(fixtures.TestBase):
+    def test_mariadb_normalized_version(self):
+        for expected, version in [
+            ((10, 2, 7), (10, 2, 7, 'MariaDB')),
+            ((10, 2, 7), (5, 6, 15, 10, 2, 7, 'MariaDB')),
+            ((10, 2, 10), (10, 2, 10, 'MariaDB')),
+            ((5, 7, 20), (5, 7, 20)),
+            ((5, 6, 15), (5, 6, 15)),
+            ((10, 2, 6),
+             (10, 2, 6, 'MariaDB', 10, 2, '6+maria~stretch', 'log')),
+        ]:
+            dialect = mysql.dialect()
+            dialect.server_version_info = version
+            eq_(
+                dialect._mariadb_normalized_version_info,
+                expected
+            )
+
+    def test_mariadb_check_warning(self):
+
+        for expect_, version in [
+            (True, (10, 2, 7, 'MariaDB')),
+            (True, (5, 6, 15, 10, 2, 7, 'MariaDB')),
+            (False, (10, 2, 10, 'MariaDB')),
+            (False, (5, 7, 20)),
+            (False, (5, 6, 15)),
+            (True, (10, 2, 6, 'MariaDB', 10, 2, '6+maria~stretch', 'log')),
+        ]:
+            dialect = mysql.dialect()
+            dialect.server_version_info = version
+            if expect_:
+                with expect_warnings(
+                        ".*before 10.2.9 has known issues regarding "
+                        "CHECK constraints"):
+                    dialect._warn_for_known_db_issues()
+            else:
+                dialect._warn_for_known_db_issues()
+
+
 class RemoveUTCTimestampTest(fixtures.TablesTest):
     """This test exists because we removed the MySQL dialect's
     override of the UTC_TIMESTAMP() function, where the commit message