web2py represent_none in SQLFORM.smartgrid in combination with date field throws exception

32 views
Skip to first unread message

David Zejda

unread,
Feb 25, 2020, 4:58:50 AM2/25/20
to web2py-users
Hi,

I found out that

SQLFORM.smartgrid(db.table_name, represent_none="") with a table table_name containing a field with date datatype throws the exception:

File "/opt/web2py3/gluon/packages/dal/pydal/validators.py", line 2335, in formatter
  year = value.year
AttributeError: 'str' object has no attribute 'year'

The problem occurs even if IS_DATE validator is not specified for the field. I have not checked it, but other validators might be affected too.

web2py 2.18.5-stable+timestamp.2019.04.08.04.22.03
python 3.7.3

Have a nice day!
David

villas

unread,
Feb 25, 2020, 1:55:41 PM2/25/20
to web2py-users
I've never used represent_none,  but it seems like a bug.

Workaround:  I guess you can try setting the field individually. Something like this..

db.mytable.somedate.represent  = lambda v,r: v.strftime('%d %b %Y')  if v else 'No Date'

Reply all
Reply to author
Forward
0 new messages