#16757 closed Bug (duplicate)
GeoDjango SpatiaLite returns unicode for dates
Reported by: | Daniel Sokolowski | Owned by: | jbronn |
---|---|---|---|
Component: | GIS | Version: | 1.3 |
Severity: | Normal | Keywords: | GeoDjango SpatiaLite dates |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
Attachments (1)
Change History (5)
by , 13 years ago
Attachment: | 16757.1.diff added |
---|
comment:1 by , 13 years ago
milestone: | → 1.4 |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 13 years ago
Resolution: | → duplicate |
---|---|
Status: | assigned → closed |
This is actually a duplicate of #16408 -- since it came first, moving everything there.