﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
16757	GeoDjango SpatiaLite returns unicode for dates	Daniel Sokolowski	jbronn	"SpatialLite db connection returns unicode for dates rather then datetime objects resulting in exceptions such as (hence date_hierarchy Admin option throws an error):

AttributeError at /admin/newsletter/newsletter/ 'unicode' object has no attribute 'day'

Resarching this issue I have discovered that a project with 'django.db.backends.sqlite3' as DB engine works properly:
{{{
	>>> User.objects.all()[0].date_joined
	datetime.datetime(2011, 9, 1, 14, 35, 43, 626241)
	>>> User.objects.all().dates('date_joined', 'day')
	[datetime.datetime(2011, 4, 4, 0, 0), datetime.datetime(2011, 7, 14, 0, 0), datetime.datetime(2011, 9, 1, 0, 0)]
	>>> print(User.objects.all().dates('date_joined', 'day').query)
	SELECT DISTINCT django_date_trunc('day', ""auth_user"".""date_joined"") FROM ""auth_user"" ORDER BY 1 ASC
}}}	
	
However the same project BUT with 'django.contrib.gis.db.backends.spatialite' as the DB engine dosen't:

{{{
	>>> User.objects.all()[0].date_joined
	datetime.datetime(2011, 9, 1, 14, 35, 43, 626241)
	>>> User.objects.all().dates('date_joined', 'day')
	[u'2011-04-04 00:00:00', u'2011-07-14 00:00:00', u'2011-09-01 00:00:00']
	>>> print(User.objects.all().dates('date_joined', 'day').query)
	SELECT DISTINCT django_date_trunc('day', ""auth_user"".""date_joined"") FROM ""auth_user"" ORDER BY 1 ASC
}}}

Furthermore in 'contrib.gis.db.backends.spatialite.base' DatabseWrapper chaning line 'self.ops = SpatiaLiteOperations(self)' 
to 'self.ops = DatabaseOperations()' returns proper values for `.dates` query.

Also method '_cursor' seems to be lacking line 'self.connection.create_function(""django_format_dtdelta"", 5, _sqlite_format_dtdelta)'
hover replacing the '## The following is the same as in django.db.backends.sqlite3.base ##' block with 'super(DatabaseWrapper, self)._cursor()'
had no effect.

After a day of trying to figure this I am still lost as to where exactly the issue might be. 
	
"	Bug	closed	GIS	1.3	Normal	duplicate	GeoDjango SpatiaLite dates		Accepted	0	0	0	0	0	0
