summaryrefslogtreecommitdiff
path: root/django/db/backends/sqlite3
diff options
context:
space:
mode:
authorJosh Smeaton <josh.smeaton@gmail.com>2015-01-17 16:03:46 +1100
committerJosh Smeaton <josh.smeaton@gmail.com>2015-01-27 14:47:38 +1100
commite56810e839db2beddc8a7b6e917158855ef381dc (patch)
tree32e9a400276b6dd92b02aa78ddddef3d55c292c1 /django/db/backends/sqlite3
parent5dff3513cc1bb998abe60f52269790268a74220c (diff)
[1.8.x] Fixed #24154 -- Backends can now check support for expressions
Backport of 8196e4bdf498acb05e6680c81f9d7bf700f4295c from master
Diffstat (limited to 'django/db/backends/sqlite3')
-rw-r--r--django/db/backends/sqlite3/features.py2
-rw-r--r--django/db/backends/sqlite3/operations.py24
2 files changed, 16 insertions, 10 deletions
diff --git a/django/db/backends/sqlite3/features.py b/django/db/backends/sqlite3/features.py
index fa5a002603..ee86469177 100644
--- a/django/db/backends/sqlite3/features.py
+++ b/django/db/backends/sqlite3/features.py
@@ -60,7 +60,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
"""Confirm support for STDDEV and related stats functions
SQLite supports STDDEV as an extension package; so
- connection.ops.check_aggregate_support() can't unilaterally
+ connection.ops.check_expression_support() can't unilaterally
rule out support for STDDEV. We need to manually check
whether the call works.
"""
diff --git a/django/db/backends/sqlite3/operations.py b/django/db/backends/sqlite3/operations.py
index ad05f88585..cd29092cd7 100644
--- a/django/db/backends/sqlite3/operations.py
+++ b/django/db/backends/sqlite3/operations.py
@@ -4,7 +4,7 @@ import datetime
import uuid
from django.conf import settings
-from django.core.exceptions import ImproperlyConfigured
+from django.core.exceptions import ImproperlyConfigured, FieldError
from django.db import utils
from django.db.backends import utils as backend_utils
from django.db.backends.base.operations import BaseDatabaseOperations
@@ -33,15 +33,21 @@ class DatabaseOperations(BaseDatabaseOperations):
limit = 999 if len(fields) > 1 else 500
return (limit // len(fields)) if len(fields) > 0 else len(objs)
- def check_aggregate_support(self, aggregate):
+ def check_expression_support(self, expression):
bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
- bad_aggregates = (aggregates.Sum, aggregates.Avg,
- aggregates.Variance, aggregates.StdDev)
- if aggregate.refs_field(bad_aggregates, bad_fields):
- raise NotImplementedError(
- 'You cannot use Sum, Avg, StdDev and Variance aggregations '
- 'on date/time fields in sqlite3 '
- 'since date/time is saved as text.')
+ bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev)
+ if isinstance(expression, bad_aggregates):
+ try:
+ output_field = expression.input_field.output_field
+ if isinstance(output_field, bad_fields):
+ raise NotImplementedError(
+ 'You cannot use Sum, Avg, StdDev and Variance aggregations '
+ 'on date/time fields in sqlite3 '
+ 'since date/time is saved as text.')
+ except FieldError:
+ # not every sub-expression has an output_field which is fine to
+ # ignore
+ pass
def date_extract_sql(self, lookup_type, field_name):
# sqlite doesn't support extract, so we fake it with the user-defined