Skip to content

Commit fb670fa

Browse files
Sergei-Rudenkovauvipy
authored andcommitted
issue #579. @@tx_isolation is deprecated since MYSQL 5.7.20, add mysq… (#581)
* issue #579. @@tx_isolation is deprecated since MYSQL 5.7.20, add mysql version check * issue #579. @@tx_isolation is deprecated since MYSQL 5.7.20, add mysql version check & add decoding for python3
1 parent 3a104b6 commit fb670fa

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

djcelery/managers.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from __future__ import absolute_import, unicode_literals
22

3+
import sys
34
import warnings
5+
import re
46

57
from functools import wraps
68
from itertools import count
@@ -189,11 +191,11 @@ def store_result(self, task_id, result, status,
189191
def warn_if_repeatable_read(self):
190192
if 'mysql' in self.current_engine().lower():
191193
cursor = self.connection_for_read().cursor()
192-
if self._is_mysql and self.server_version_info >= (5, 7, 20):
193-
ti = cursor.execute("SELECT @@transaction_isolation")
194+
if self._get_server_version_info_for_mysql() >= (5, 7, 20):
195+
ok = cursor.execute("SELECT @@transaction_isolation")
194196
else:
195-
ti = cursor.execute("SELECT @@tx_isolation")
196-
if ti:
197+
ok = cursor.execute("SELECT @@tx_isolation")
198+
if ok:
197199
isolation = cursor.fetchone()[0]
198200
if isolation == 'REPEATABLE-READ':
199201
warnings.warn(TxIsolationWarning(
@@ -202,6 +204,24 @@ def warn_if_repeatable_read(self):
202204
'may give outdated results. Be sure to commit the '
203205
'transaction for each poll iteration.'))
204206

207+
def _get_server_version_info_for_mysql(self):
208+
cursor = self.connection_for_read().cursor()
209+
cursor.execute("select version()")
210+
val = cursor.fetchone()[0]
211+
cursor.close()
212+
213+
if sys.version_info >= (3, 0) and isinstance(val, bytes):
214+
val = val.decode()
215+
216+
version = []
217+
r = re.compile(r"[.\-]")
218+
for n in r.split(val):
219+
try:
220+
version.append(int(n))
221+
except ValueError:
222+
version.append(n)
223+
return tuple(version)
224+
205225

206226
class TaskSetManager(ResultManager):
207227
"""Manager for :class:`celery.models.TaskSet` models."""

0 commit comments

Comments
 (0)