Code

Opened 9 years ago

Closed 8 years ago

#1062 closed defect (fixed)

[patch] typecast on date fails

Reported by: cmaloney@… Owned by: adrian
Component: Database layer (models, ORM) Version: master
Severity: normal Keywords:
Cc: nesh@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When using date based generic views with SQLite, the following error occurrs:

Exception Type: ValueError
Exception Value: need more than 1 value to unpack
Exception Location: /usr/local/lib/python2.4/site-packages/django/core/db/typecasts.py in typecast_timestamp, line 22

It seems the typecast for date assumes date+time, whereas the DateField() comes back with only a date.
I have worked around this problem using the following patch:

--- typecasts.py 2005-10-21 11:11:48.000000000 +1000
+++ /usr/lib/python2.4/site-packages/Django-0.90-py2.4.egg/django/core/db/typecasts.py 2005-12-14 12:57:53.000000000 +1100
@@ -20,7 +20,11 @@

# "2005-07-29 15:48:00.590358-05"
# "2005-07-29 09:56:00-05"
if not s: return None

+ try:

d, t = s.split()

+ except ValueError:
+ d = s
+ t = '00:00:01'

# Extract timezone information, if it exists. Currently we just throw
# it away, but in the future we may make use of it.
if '-' in t:

Attachments (1)

typecast.diff (539 bytes) - added by Nebojša Đorđević - nesh <nesh@…> 9 years ago.
slightly different patch

Download all attachments as: .zip

Change History (5)

comment:1 Changed 9 years ago by anonymous

  • Version set to SVN

comment:2 Changed 9 years ago by Nebojša Đorđević - nesh <nesh@…>

  • Cc nesh@… added

Changed 9 years ago by Nebojša Đorđević - nesh <nesh@…>

slightly different patch

comment:3 Changed 9 years ago by Nebojša Đorđević - nesh <nesh@…>

  • Summary changed from typecast on date fails to [patch] typecast on date fails

Another sollution is to not use DateField alltogether, use only DateTimeField which works OK.

comment:4 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [1971]) Fixed #1062 -- Fixed database typecasting bug for DateTimeFields in SQLite. Thanks, Nesh and cmaloney

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.