Just as a quick check, I replaced the new parse_datetime function with the 
old, and all is well.

Brad

On Friday, August 31, 2012 3:49:32 PM UTC-5, Brad Miller wrote:
>
> Here is the value that printed:
>
> 2012-07-05 02:36:50
>
> This field is declared in the model as:    Field('timestamp','datetime'),
>
> The old parse_datetime function seems to skip over the date part before it 
> does the split on the -
>
> Here's the old one:
>
>     def parse_datetime(self, value, field_type):
>         if not isinstance(value, datetime.datetime):
>     (y, m, d) = map(int,str(value)[:10].strip().split('-'))
>             time_items = map(int,str(value)[11:19].strip().split(':')[:3])
>             if len(time_items) == 3:
> (h, mi, s) = time_items
>             else:
>                 (h, mi, s) = time_items + [0]
>             value = datetime.datetime(y, m, d, h, mi, s)
>         return value
>
> Brad
>
> On Friday, August 31, 2012 3:33:22 PM UTC-5, Massimo Di Pierro wrote:
>>
>> This is the code that causes the problem to you:
>>
>> def parse_datetime(self, value, field_type):
>>         if not isinstance(value, datetime.datetime):
>>             ....
>>             elif '-' in value:
>>                 value,tz = value.split('-')
>>
>> This function is called when parsing data retrieved from database. The 
>> reason it is failing is that data is corrupted (contains more than one dash 
>> and that is not allowed by ISO standard). What database (my guess is 
>> sqlite, which allows you to change a string field into a datetime while 
>> leaving data in there). Can you add a print statement and see what the data 
>> looks like:
>>
>> def parse_datetime(self, value, field_type):
>>         if not isinstance(value, datetime.datetime):
>>             print value
>>             ....
>>
>> Let me know it may help understand how the data got in there.
>>
>> On Friday, 31 August 2012 14:53:16 UTC-5, Brad Miller wrote:
>>>
>>> I just upgraded my app to the latest 2.0.3 (stable)  and while checking 
>>> some of my pages got the following error:
>>>
>>> Traceback (most recent call last):
>>>   File "/Users/bmiller/Beta/web2py/gluon/restricted.py", line 209, in 
>>> restricted
>>>     exec ccode in environment
>>>   File 
>>> "/Users/bmiller/Beta/web2py/applications/runestone/controllers/admin.py", 
>>> line 160, in <module>
>>>   File "/Users/bmiller/Beta/web2py/gluon/globals.py", line 185, in 
>>> <lambda>
>>>     self._caller = lambda f: f()
>>>   File "/Users/bmiller/Beta/web2py/gluon/tools.py", line 2780, in f
>>>     return action(*a, **b)
>>>   File 
>>> "/Users/bmiller/Beta/web2py/applications/runestone/controllers/admin.py", 
>>> line 116, in studentactivity
>>>     db.useinfo.sid, count, last, groupby=db.useinfo.sid, orderby=count)
>>>   File "/Users/bmiller/Beta/web2py/gluon/dal.py", line 8692, in select
>>>     return adapter.select(self.query,fields,attributes)
>>>   File "/Users/bmiller/Beta/web2py/gluon/dal.py", line 2029, in select
>>>     return super(SQLiteAdapter, self).select(query, fields, attributes)
>>>   File "/Users/bmiller/Beta/web2py/gluon/dal.py", line 1529, in select
>>>     return self._select_aux(sql,fields,attributes)
>>>   File "/Users/bmiller/Beta/web2py/gluon/dal.py", line 1510, in 
>>> _select_aux
>>>     return processor(rows,fields,self._colnames,cacheable=cacheable)
>>>   File "/Users/bmiller/Beta/web2py/gluon/dal.py", line 1886, in parse
>>>     fields[j].type,blob_decode)
>>>   File "/Users/bmiller/Beta/web2py/gluon/dal.py", line 1718, in 
>>> parse_value
>>>     return self.parsemap[key](value,field_type)
>>>   File "/Users/bmiller/Beta/web2py/gluon/dal.py", line 1753, in 
>>> parse_datetime
>>>     value,tz = value.split('-')
>>> ValueError: too many values to unpack
>>>
>>> This is the result of this this query code, which continues to work 
>>> under 1.99.7
>>>
>>>     count = db.useinfo.id.count()
>>>     last = db.useinfo.timestamp.max()
>>>     res = db(db.useinfo.course_id==course.course_id).select(
>>>         db.useinfo.sid, count, last, groupby=db.useinfo.sid, 
>>> orderby=count)
>>>
>>> I'm assuming this is some kind of regression since the same code is 
>>> working in 1.99.7, but maybe I'm doing something that I could do  but no 
>>> longer should??
>>>
>>> Brad
>>>
>>>

-- 



Reply via email to