'tzinfo' is an invalid keyword argument for this function

3,231 views
Skip to first unread message

Graham Robbins

unread,
Jan 12, 2014, 7:00:15 AM1/12/14
to web...@googlegroups.com
IS_DATE() formatter sets
  
d = datetime.date(year, value.month, value.day)

and if self.timezone is not None it calls d.replace with the tzinfo keyword, this results in the exception:

  File "/home/www-data/web2py/gluon/validators.py", line 2263, in formatter
    d
= d.replace(tzinfo=utc).astimezone(self.timezone)
TypeError: 'tzinfo' is an invalid keyword argument for this function

Changing d to be a datetime.datetime instance returns the formatted date.

The relevant field is:

Field('deadline', 'date', requires=IS_DATE(timezone=pytz.timezone('America/Chicago'),
 
format='%Y-%m-%d'))

Should I be doing anything differently or does IS_DATE() need to be changed?

Web2py: 2.8.2-stable+timestamp.2013.11.28.13.54.07
Python: 2.7.3

Massimo Di Pierro

unread,
Jan 12, 2014, 10:20:38 AM1/12/14
to web...@googlegroups.com
This is wrong in the code but for logical reason. IS_DATE should not accept the timezone info. That is because unless you know a time of the time, it is not possible to determine the date (and time of the day) in the other timezone. This is reflected in the fact that datetime.date does not take a timezone while datetime.datetime.

There are two ways out:
1) drop the IS_DATE(timezone) argument
2) make an implicit assumption about the time of date (always 00:00:00?).

Suggestions?

Anthony

unread,
Jan 12, 2014, 10:39:30 AM1/12/14
to web...@googlegroups.com
I would lean toward #2 (your default seems reasonable).

Graham Robbins

unread,
Jan 13, 2014, 3:00:20 AM1/13/14
to web...@googlegroups.com
Option 2 is fine for me, changing

d = datetime.date(year, value.month, value.day)

to

d = datetime.datetime(year, value.month, value.day)

accomplishes this with implicit defaults
Reply all
Reply to author
Forward
0 new messages