summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql/operations.py
diff options
context:
space:
mode:
authorTom Forbes <tom@tomforb.es>2018-07-09 19:59:42 +0100
committerTim Graham <timograham@gmail.com>2018-07-09 14:59:42 -0400
commit45c035c823bfbd642dc1490f1c555316af403c4c (patch)
tree6378127ba9f0bca3aa48dae9ecc8683a3123bf12 /django/db/backends/mysql/operations.py
parent7d6fe18dde78d07e5f0249e21419f19a67ca4aa4 (diff)
downloaddjango-45c035c823bfbd642dc1490f1c555316af403c4c.tar.gz
Refs #29548 -- Fixed non-GIS test failures on MariaDB.
Diffstat (limited to 'django/db/backends/mysql/operations.py')
-rw-r--r--django/db/backends/mysql/operations.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py
index 31f92ac5cd..ddeb128d32 100644
--- a/django/db/backends/mysql/operations.py
+++ b/django/db/backends/mysql/operations.py
@@ -1,3 +1,4 @@
+import decimal
import uuid
from django.conf import settings
@@ -260,10 +261,22 @@ class DatabaseOperations(BaseDatabaseOperations):
def binary_placeholder_sql(self, value):
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):
lhs_sql, lhs_params = lhs
rhs_sql, rhs_params = rhs
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 (
"((TIME_TO_SEC(%(lhs)s) * 1000000 + MICROSECOND(%(lhs)s)) -"
" (TIME_TO_SEC(%(rhs)s) * 1000000 + MICROSECOND(%(rhs)s)))"