summaryrefslogtreecommitdiff
path: root/django/contrib/gis/db/models/sql/compiler.py
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2011-09-10 22:53:26 +0000
committerJustin Bronn <jbronn@gmail.com>2011-09-10 22:53:26 +0000
commit2918c3de74d1abe571b6c1eeb35e2899c39d880e (patch)
treec4c9278926479916992406e24918b9f643a5f4a7 /django/contrib/gis/db/models/sql/compiler.py
parent8e1226b4a00a0d26752b26d0ebf21ff8c5a247ad (diff)
Fixed #14648 -- Fixed annotated date querysets when `GeoManager` is used. Thanks, codysoyland, for the bug report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16796 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/contrib/gis/db/models/sql/compiler.py')
-rw-r--r--django/contrib/gis/db/models/sql/compiler.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/django/contrib/gis/db/models/sql/compiler.py b/django/contrib/gis/db/models/sql/compiler.py
index 782ce78368..405a000f42 100644
--- a/django/contrib/gis/db/models/sql/compiler.py
+++ b/django/contrib/gis/db/models/sql/compiler.py
@@ -1,7 +1,7 @@
from itertools import izip
-from django.db.backends.util import truncate_name
+from django.db.backends.util import truncate_name, typecast_timestamp
from django.db.models.sql import compiler
-from django.db.models.sql.constants import TABLE_NAME
+from django.db.models.sql.constants import TABLE_NAME, MULTI
from django.db.models.sql.query import get_proxied_model
SQLCompiler = compiler.SQLCompiler
@@ -194,7 +194,7 @@ class GeoSQLCompiler(compiler.SQLCompiler):
# We resolve the rest of the columns if we're on Oracle or if
# the `geo_values` attribute is defined.
for value, field in map(None, row[index_start:], fields):
- values.append(self.query.convert_values(value, field, connection=self.connection))
+ values.append(self.query.convert_values(value, field, self.connection))
else:
values.extend(row[index_start:])
return tuple(values)
@@ -275,4 +275,24 @@ class SQLAggregateCompiler(compiler.SQLAggregateCompiler, GeoSQLCompiler):
pass
class SQLDateCompiler(compiler.SQLDateCompiler, GeoSQLCompiler):
- pass
+ """
+ This is overridden for GeoDjango to properly cast date columns, since
+ `GeoQuery.resolve_columns` is used for spatial values.
+ See #14648, #16757.
+ """
+ def results_iter(self):
+ if self.connection.ops.oracle:
+ from django.db.models.fields import DateTimeField
+ fields = [DateTimeField()]
+ else:
+ needs_string_cast = self.connection.features.needs_datetime_string_cast
+
+ offset = len(self.query.extra_select)
+ for rows in self.execute_sql(MULTI):
+ for row in rows:
+ date = row[offset]
+ if self.connection.ops.oracle:
+ date = self.resolve_columns(row, fields)[offset]
+ elif needs_string_cast:
+ date = typecast_timestamp(str(date))
+ yield date