]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Remove deprecation warnings mysql5 7 20
authorDaniel Thorell <(none)>
Fri, 20 Oct 2017 16:59:55 +0000 (12:59 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 23 Oct 2017 23:06:28 +0000 (19:06 -0400)
MySQL 5.7.20 now warns for use of the @tx_isolation variable; a version
check is now performed and uses @transaction_isolation instead
to prevent this warning.

For 1.1, also backport our_warn() test fixture fix from
9f0fb6c601 1.2 branch.

(cherry picked from commit 41cfe44b5e5806b3d3b13949e41dbb347bfa29e1)
Co-authored by: Mike Bayer <mike_mp@zzzcomputing.com>
Fixes: #4120
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/391
Change-Id: I4d2e04df760c5351a71dde8b32145cdc69fa6115

doc/build/changelog/unreleased_11/4120.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/testing/assertions.py

diff --git a/doc/build/changelog/unreleased_11/4120.rst b/doc/build/changelog/unreleased_11/4120.rst
new file mode 100644 (file)
index 0000000..e84c1ac
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: bug, mysql
+    :tickets: 4120
+    :versions: 1.2.0b4
+
+    MySQL 5.7.20 now warns for use of the @tx_isolation variable; a version
+    check is now performed and uses @transaction_isolation instead
+    to prevent this warning.
index 0abbf6b4b7e16b2f06e053c875d2205ea8456f38..2ccdb9599d257c38fb9eca5757c67d2b1b990b9e 100644 (file)
@@ -1573,7 +1573,10 @@ class MySQLDialect(default.DefaultDialect):
 
     def get_isolation_level(self, connection):
         cursor = connection.cursor()
-        cursor.execute('SELECT @@tx_isolation')
+        if self._is_mysql and self.server_version_info >= (5, 7, 20):
+            cursor.execute('SELECT @@transaction_isolation')
+        else:
+            cursor.execute('SELECT @@tx_isolation')
         val = cursor.fetchone()[0]
         cursor.close()
         if util.py3k and isinstance(val, bytes):
@@ -1740,6 +1743,10 @@ class MySQLDialect(default.DefaultDialect):
     def _is_mariadb(self):
         return 'MariaDB' in self.server_version_info
 
+    @property
+    def _is_mysql(self):
+        return 'MariaDB' not in self.server_version_info
+
     @property
     def _is_mariadb_102(self):
         return self._is_mariadb and \
index 3ee38937f746cee88db4bdb684e9fd984b950c5a..591ec01c26ec4046689f2b54506efe795d692dae 100644 (file)
@@ -130,9 +130,17 @@ def _expect_warnings(exc_cls, messages, regex=True, assert_=True,
 
     real_warn = warnings.warn
 
-    def our_warn(msg, exception, *arg, **kw):
-        if not issubclass(exception, exc_cls):
-            return real_warn(msg, exception, *arg, **kw)
+    def our_warn(msg, *arg, **kw):
+        if isinstance(msg, exc_cls):
+            exception = msg
+            msg = str(exception)
+        elif arg:
+            exception = arg[0]
+        else:
+            exception = None
+
+        if not exception or not issubclass(exception, exc_cls):
+            return real_warn(msg, *arg, **kw)
 
         if not filters:
             return
@@ -143,7 +151,7 @@ def _expect_warnings(exc_cls, messages, regex=True, assert_=True,
                 seen.discard(filter_)
                 break
         else:
-            real_warn(msg, exception, *arg, **kw)
+            real_warn(msg, *arg, **kw)
 
     with mock.patch("warnings.warn", our_warn):
         yield