Error with datetime.

79 views
Skip to first unread message

Maurice Waka

unread,
Nov 7, 2018, 1:34:41 PM11/7/18
to web2py-users
I'm  getting this error when using datetime;
Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
 
Traceback (most recent call last):
 
File "/home/maurice/web2py/gluon/restricted.py", line 219, in restricted
 
exec(ccode, environment)
 
File "/home/maurice/web2py/applications/Welln/controllers/default.py", line 616, in <module>
 
File "/home/maurice/web2py/gluon/globals.py", line 421, in <lambda>
 
self._caller = lambda f: f()
 
File "/home/maurice/web2py/gluon/tools.py", line 3867, in f
 
return action(*a, **b)
 
File "/home/maurice/web2py/applications/Welln/controllers/default.py", line 389, in diary
 results
= rows(db.diary.today == diary_date).select()
 
File "/usr/local/lib/python2.7/dist-packages/pydal/objects.py", line 2250, in select
 
return adapter.select(self.query, fields, attributes)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/mongo.py", line 233, in select
 
return self.__select(query, fields, **attributes)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/mongo.py", line 294, in __select
 groupby
=groupby, distinct=distinct, having=having)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/mongo.py", line 621, in __init__
 
self.query_dict = adapter.expand(self.query)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/mongo.py", line 177, in _expand
 result
= op(first, second, **optional_args)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/dialects/mongo.py", line 109, in _and
 
self.expand(second, query_env=query_env)]}
 
File "/usr/local/lib/python2.7/dist-packages/pydal/dialects/__init__.py", line 96, in expand
 
return self.adapter.expand(*args, **kwargs)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/mongo.py", line 177, in _expand
 result
= op(first, second, **optional_args)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/dialects/mongo.py", line 57, in wrap
 
return f(self, first, second, *args, pipeline=pipeline, **kwargs)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/dialects/mongo.py", line 144, in eq
 
self.expand(second, first.type, query_env=query_env)}
 
File "/usr/local/lib/python2.7/dist-packages/pydal/dialects/__init__.py", line 96, in expand
 
return self.adapter.expand(*args, **kwargs)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/mongo.py", line 191, in _expand
 result
= self.represent(expression, field_type)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/mongo.py", line 199, in represent
 
return super(Mongo, self).represent(obj, field_type)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/adapters/base.py", line 335, in represent
 
return self.representer.represent(obj, field_type)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/representers/__init__.py", line 251, in represent
 rv
= self.get_representer_for_type(field_type)(rv, field_type)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/representers/__init__.py", line 139, in __call__
 
return self.adapt(self.call(value, field_type))
 
File "/usr/local/lib/python2.7/dist-packages/pydal/representers/__init__.py", line 136, in _call
 
return self.inner_call(value)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/representers/__init__.py", line 124, in _inner_call
 
return self.obj.f(self.representer, value, **kwargs)
 
File "/usr/local/lib/python2.7/dist-packages/pydal/representers/mongo.py", line 28, in _date
 
return datetime.datetime.combine(value, t)
TypeError: combine() argument 1 must be datetime.date, not str


What could be the issue and how do i solve it.
My code is:

from datetime import date
   
if request.vars.current_date == None:
        diary_date
= date.today()
   
else:
        diary_date
= request.vars.current_date
    session
.date = diary_date


rows
= db(db.calcdiary.created_by == auth.user_id)
    results
= rows(db.calcdiary.today == diary_date).select()

黄祥

unread,
Nov 7, 2018, 6:27:16 PM11/7/18
to web2py-users
from error traceback seems like must convert the str to datetime.date
ref:

best regards,
stifan

Maurice Waka

unread,
Nov 7, 2018, 10:43:27 PM11/7/18
to web...@googlegroups.com
I'm still getting the same error when changing the dates.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/AdcoDH7_M-c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lovedie JC

unread,
Nov 7, 2018, 11:09:01 PM11/7/18
to web...@googlegroups.com
When using sqlite, I don't get the errors, but using Mongodb brings up the same error.

You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

Dave S

unread,
Nov 8, 2018, 3:33:36 AM11/8/18
to web2py-users

From the traceback, it's not clear to me if the "str" is from  Maurice's code, or the Mongo adapter.  One way to check would be to use sqlite3 for a trial.

BTW, the request object has a datetime object in it (request.now) although I also have code that uses datetime.datetime.now().

/dps


/dps

Maurice Waka

unread,
Nov 8, 2018, 7:32:16 AM11/8/18
to web...@googlegroups.com
Same code using storage.sqlite is ok but when I switched to MongoDB which intent to use in future, the error comes up.

Reply all
Reply to author
Forward
0 new messages