Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed #19360 -- Raised an explicit exception for aggregates on date/time... #579

Closed
wants to merge 1 commit into from

2 participants

@chrismedrela

... fields in sqlite3.

@claudep
Collaborator

A new pull request with tests and docs has been opened and referenced on the ticket.

@claudep claudep closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 10, 2012
  1. Fixed #19360 -- Raised an explicit exception for aggregates on date/t…

    Christopher Medrela authored
    …ime fields in sqlite3.
This page is out of date. Refresh to see the latest.
View
14 django/db/backends/sqlite3/base.py
@@ -18,6 +18,8 @@
from django.db.backends.sqlite3.client import DatabaseClient
from django.db.backends.sqlite3.creation import DatabaseCreation
from django.db.backends.sqlite3.introspection import DatabaseIntrospection
+from django.db.models import fields
+from django.db.models.sql import aggregates
from django.utils.dateparse import parse_date, parse_datetime, parse_time
from django.utils.functional import cached_property
from django.utils.safestring import SafeBytes
@@ -127,6 +129,18 @@ def bulk_batch_size(self, fields, objs):
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):
+ # fix for ticket 19360
+ bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField)
+ bad_aggregates = (aggregates.Sum, aggregates.Avg,
+ aggregates.Variance, aggregates.StdDev)
+ if isinstance(aggregate.source, bad_fields) and \
+ isinstance(aggregate, bad_aggregates):
+ raise NotImplementedError(
+ 'You cannot use Sum, Avg, StdDev and Variance aggregations '
+ 'on date/time fields in sqlite3 '
+ 'since date/time is saved as text.')
+
def date_extract_sql(self, lookup_type, field_name):
# sqlite doesn't support extract, so we fake it with the user-defined
# function django_extract that's registered in connect(). Note that
View
2  django/db/models/sql/query.py
@@ -119,7 +119,7 @@ def __init__(self, model, where=WhereNode):
self.filter_is_sticky = False
self.included_inherited_models = {}
- # SQL-related attributes
+ # SQL-related attributes
# Select and related select clauses as SelectInfo instances.
# The select is used for cases where we want to set up the select
# clause to contain other than default fields (values(), annotate(),
Something went wrong with that request. Please try again.