Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#16757 closed Bug (duplicate)

GeoDjango SpatiaLite returns unicode for dates

Reported by: danols 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)

16757.1.diff (6.4 KB) - added by jbronn 3 years ago.

Download all attachments as: .zip

Change History (5)

Changed 3 years ago by jbronn

comment:1 Changed 3 years ago by jbronn

  • milestone set to 1.4
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to jbronn
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 3 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 3 years ago by jbronn

  • Resolution set to duplicate
  • Status changed from assigned to closed

This is actually a duplicate of #16408 -- since it came first, moving everything there.

comment:4 Changed 3 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.