summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Čihař <michal@cihar.com>2018-07-05 18:11:49 +0200
committerTim Graham <timograham@gmail.com>2018-07-05 12:12:11 -0400
commit1645471348ac6012ad9444742f6e572ecf7c993b (patch)
tree26290113281bb007c9a97b3b50609672f20f3e7d
parent2ce830e683ad2ce60cfdc0d77866fc2e55a48b9f (diff)
[2.0.x] Fixed #29544 -- Fixed regex lookup on MariaDB.
Regression in 42490768441701bc02255b22df8e6894cbe487c7. Backport of 39e287d8bff50e9f91f3f4471088c1946aa6a76c from master
-rw-r--r--django/db/backends/mysql/base.py16
-rw-r--r--django/db/backends/mysql/operations.py4
-rw-r--r--docs/releases/2.0.8.txt3
3 files changed, 16 insertions, 7 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index 34e8d41f03..8ade4b279c 100644
--- a/django/db/backends/mysql/base.py
+++ b/django/db/backends/mysql/base.py
@@ -339,11 +339,19 @@ class DatabaseWrapper(BaseDatabaseWrapper):
return True
@cached_property
- def mysql_version(self):
+ def mysql_server_info(self):
with self.temporary_connection() as cursor:
cursor.execute('SELECT VERSION()')
- server_info = cursor.fetchone()[0]
- match = server_version_re.match(server_info)
+ return cursor.fetchone()[0]
+
+ @cached_property
+ def mysql_version(self):
+ match = server_version_re.match(self.mysql_server_info)
if not match:
- raise Exception('Unable to determine MySQL version from version string %r' % server_info)
+ raise Exception('Unable to determine MySQL version from version string %r' % self.mysql_server_info)
return tuple(int(x) for x in match.groups())
+
+ @cached_property
+ def mysql_is_mariadb(self):
+ # MariaDB isn't officially supported.
+ return 'mariadb' in self.mysql_server_info.lower()
diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py
index d9cb6a27c0..a9b5b67dbb 100644
--- a/django/db/backends/mysql/operations.py
+++ b/django/db/backends/mysql/operations.py
@@ -275,8 +275,8 @@ class DatabaseOperations(BaseDatabaseOperations):
def regex_lookup(self, lookup_type):
# REGEXP BINARY doesn't work correctly in MySQL 8+ and REGEXP_LIKE
- # doesn't exist in MySQL 5.6.
- if self.connection.mysql_version < (8, 0, 0):
+ # doesn't exist in MySQL 5.6 or in MariaDB.
+ if self.connection.mysql_version < (8, 0, 0) or self.connection.mysql_is_mariadb:
if lookup_type == 'regex':
return '%s REGEXP BINARY %s'
return '%s REGEXP %s'
diff --git a/docs/releases/2.0.8.txt b/docs/releases/2.0.8.txt
index 0e6e081443..c83a60cf81 100644
--- a/docs/releases/2.0.8.txt
+++ b/docs/releases/2.0.8.txt
@@ -9,4 +9,5 @@ Django 2.0.8 fixes several bugs in 2.0.7.
Bugfixes
========
-* ...
+* Fixed a regression in Django 2.0.7 that broke the ``regex`` lookup on MariaDB
+ (even though MariaDB isn't officially supported) (:ticket:`29544`).