mirror of https://github.com/django/django.git
Fixed #28794 -- Fixed tx_isolation deprecation warning on MySQL 5.7.20+.
This commit is contained in:
parent
bc95314ca6
commit
967450a3bf
|
@ -222,7 +222,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
', '.join("'%s'" % s for s in sorted(self.isolation_levels))
|
', '.join("'%s'" % s for s in sorted(self.isolation_levels))
|
||||||
))
|
))
|
||||||
# The variable assignment form of setting transaction isolation
|
# The variable assignment form of setting transaction isolation
|
||||||
# levels will be used, e.g. "set tx_isolation='repeatable-read'".
|
# levels will be used, e.g. "set transaction_isolation='repeatable-read'".
|
||||||
isolation_level = isolation_level.replace(' ', '-')
|
isolation_level = isolation_level.replace(' ', '-')
|
||||||
self.isolation_level = isolation_level
|
self.isolation_level = isolation_level
|
||||||
kwargs.update(options)
|
kwargs.update(options)
|
||||||
|
@ -231,6 +231,10 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
def get_new_connection(self, conn_params):
|
def get_new_connection(self, conn_params):
|
||||||
return Database.connect(**conn_params)
|
return Database.connect(**conn_params)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def transaction_isolation_variable(self):
|
||||||
|
return 'tx_isolation' if self.mysql_version < (5, 7, 20) else 'transaction_isolation'
|
||||||
|
|
||||||
def init_connection_state(self):
|
def init_connection_state(self):
|
||||||
assignments = []
|
assignments = []
|
||||||
if self.features.is_sql_auto_is_null_enabled:
|
if self.features.is_sql_auto_is_null_enabled:
|
||||||
|
@ -241,7 +245,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
assignments.append('SQL_AUTO_IS_NULL = 0')
|
assignments.append('SQL_AUTO_IS_NULL = 0')
|
||||||
|
|
||||||
if self.isolation_level:
|
if self.isolation_level:
|
||||||
assignments.append("TX_ISOLATION = '%s'" % self.isolation_level)
|
assignments.append("%s = '%s'" % (self.transaction_isolation_variable, self.isolation_level))
|
||||||
|
|
||||||
if assignments:
|
if assignments:
|
||||||
with self.cursor() as cursor:
|
with self.cursor() as cursor:
|
||||||
|
|
|
@ -38,7 +38,7 @@ class IsolationLevelTests(TestCase):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_isolation_level(connection):
|
def get_isolation_level(connection):
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
cursor.execute("SELECT @@session.tx_isolation")
|
cursor.execute("SELECT @@session.%s" % connection.transaction_isolation_variable)
|
||||||
return cursor.fetchone()[0]
|
return cursor.fetchone()[0]
|
||||||
|
|
||||||
def test_auto_is_null_auto_config(self):
|
def test_auto_is_null_auto_config(self):
|
||||||
|
|
Loading…
Reference in New Issue