diff options
| author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2017-11-15 01:40:44 +0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-11-14 15:40:44 -0500 |
| commit | 967450a3bf940c43db891fe1e2ef3bcf73456ff8 (patch) | |
| tree | 2f06538979adff20bab776cb5588c6ceafa76c45 /django | |
| parent | bc95314ca6af0b5e993ae07fdc7d8e6166d3b8ca (diff) | |
Fixed #28794 -- Fixed tx_isolation deprecation warning on MySQL 5.7.20+.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/mysql/base.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 57ef2ad2a0..3b1cc84f82 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -222,7 +222,7 @@ class DatabaseWrapper(BaseDatabaseWrapper): ', '.join("'%s'" % s for s in sorted(self.isolation_levels)) )) # 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(' ', '-') self.isolation_level = isolation_level kwargs.update(options) @@ -231,6 +231,10 @@ class DatabaseWrapper(BaseDatabaseWrapper): def get_new_connection(self, 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): assignments = [] if self.features.is_sql_auto_is_null_enabled: @@ -241,7 +245,7 @@ class DatabaseWrapper(BaseDatabaseWrapper): assignments.append('SQL_AUTO_IS_NULL = 0') 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: with self.cursor() as cursor: |
