Refs #29548 -- Fixed non-GIS test failures on MariaDB.

This commit is contained in:
Tom Forbes 2018-07-09 19:59:42 +01:00 committed by Tim Graham
parent 7d6fe18dde
commit 45c035c823
3 changed files with 20 additions and 3 deletions

View File

@ -80,18 +80,20 @@ class DatabaseFeatures(BaseDatabaseFeatures):
@cached_property @cached_property
def supports_over_clause(self): def supports_over_clause(self):
if self.connection.mysql_is_mariadb:
return self.connection.mysql_version >= (10, 2)
return self.connection.mysql_version >= (8, 0, 2) return self.connection.mysql_version >= (8, 0, 2)
@cached_property @cached_property
def has_select_for_update_skip_locked(self): def has_select_for_update_skip_locked(self):
return self.connection.mysql_version >= (8, 0, 1) return not self.connection.mysql_is_mariadb and self.connection.mysql_version >= (8, 0, 1)
has_select_for_update_nowait = has_select_for_update_skip_locked has_select_for_update_nowait = has_select_for_update_skip_locked
@cached_property @cached_property
def needs_explain_extended(self): def needs_explain_extended(self):
# EXTENDED is deprecated (and not required) in 5.7 and removed in 8.0. # EXTENDED is deprecated (and not required) in MySQL 5.7.
return self.connection.mysql_version < (5, 7) return not self.connection.mysql_is_mariadb and self.connection.mysql_version < (5, 7)
@cached_property @cached_property
def supports_transactions(self): def supports_transactions(self):

View File

@ -1,3 +1,4 @@
import decimal
import uuid import uuid
from django.conf import settings from django.conf import settings
@ -260,10 +261,22 @@ class DatabaseOperations(BaseDatabaseOperations):
def binary_placeholder_sql(self, value): def binary_placeholder_sql(self, value):
return '_binary %s' if value is not None and not hasattr(value, 'as_sql') else '%s' return '_binary %s' if value is not None and not hasattr(value, 'as_sql') else '%s'
def convert_durationfield_value(self, value, expression, connection):
# DurationFields can return a Decimal in MariaDB.
if isinstance(value, decimal.Decimal):
value = float(value)
return super().convert_durationfield_value(value, expression, connection)
def subtract_temporals(self, internal_type, lhs, rhs): def subtract_temporals(self, internal_type, lhs, rhs):
lhs_sql, lhs_params = lhs lhs_sql, lhs_params = lhs
rhs_sql, rhs_params = rhs rhs_sql, rhs_params = rhs
if internal_type == 'TimeField': if internal_type == 'TimeField':
if self.connection.mysql_is_mariadb:
# MariaDB includes the microsecond component in TIME_TO_SEC as
# a decimal. MySQL returns an integer without microseconds.
return '((TIME_TO_SEC(%(lhs)s) - TIME_TO_SEC(%(rhs)s)) * 1000000)' % {
'lhs': lhs_sql, 'rhs': rhs_sql
}, lhs_params + rhs_params
return ( return (
"((TIME_TO_SEC(%(lhs)s) * 1000000 + MICROSECOND(%(lhs)s)) -" "((TIME_TO_SEC(%(lhs)s) * 1000000 + MICROSECOND(%(lhs)s)) -"
" (TIME_TO_SEC(%(rhs)s) * 1000000 + MICROSECOND(%(rhs)s)))" " (TIME_TO_SEC(%(rhs)s) * 1000000 + MICROSECOND(%(rhs)s)))"

View File

@ -22,11 +22,13 @@ class TestFeatures(TestCase):
def test_skip_locked_no_wait(self): def test_skip_locked_no_wait(self):
with mock.MagicMock() as _connection: with mock.MagicMock() as _connection:
_connection.mysql_version = (8, 0, 1) _connection.mysql_version = (8, 0, 1)
_connection.mysql_is_mariadb = False
database_features = DatabaseFeatures(_connection) database_features = DatabaseFeatures(_connection)
self.assertTrue(database_features.has_select_for_update_skip_locked) self.assertTrue(database_features.has_select_for_update_skip_locked)
self.assertTrue(database_features.has_select_for_update_nowait) self.assertTrue(database_features.has_select_for_update_nowait)
with mock.MagicMock() as _connection: with mock.MagicMock() as _connection:
_connection.mysql_version = (8, 0, 0) _connection.mysql_version = (8, 0, 0)
_connection.mysql_is_mariadb = False
database_features = DatabaseFeatures(_connection) database_features = DatabaseFeatures(_connection)
self.assertFalse(database_features.has_select_for_update_skip_locked) self.assertFalse(database_features.has_select_for_update_skip_locked)
self.assertFalse(database_features.has_select_for_update_nowait) self.assertFalse(database_features.has_select_for_update_nowait)