]> 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>
Fri, 20 Oct 2017 20:08:47 +0000 (16:08 -0400)
Fixed regression from 1.2.0b3 where "MariaDB" version comparison can
fail for some particular MariaDB version strings under Python 3.

Change-Id: Iedf49f40c1614ccedf63e0fa26719dd704da104d
Fixes: #4115
doc/build/changelog/unreleased_12/4115.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mysql/base.py
test/dialect/mysql/test_dialect.py

diff --git a/doc/build/changelog/unreleased_12/4115.rst b/doc/build/changelog/unreleased_12/4115.rst
new file mode 100644 (file)
index 0000000..f94f600
--- /dev/null
@@ -0,0 +1,6 @@
+:change:
+    :tags: bug, mysql
+    :tickets: 4115
+
+    Fixed regression from 1.2.0b3 where "MariaDB" version comparison can
+    fail for some particular MariaDB version strings under Python 3.
\ No newline at end of file
index 5f0b45a45d99ff1e885dcd1ca148f1ed26ae544d..5acb9a005773353ab8e203151b31cc2b8156bdd9 100644 (file)
@@ -1894,8 +1894,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