As book says... "DAL fields may have a compute attribute. This must be a function (or lambda) that takes a Row object and returns a value for the field."
So, lambda for computed fields gets all fields and returns just one field. I think it work on DAL level, not on FORM level. On 12/19/11, Richard Vézina <ml.richard.vez...@gmail.com> wrote: > I don't get all my db.table fields form define_table fields defined... > > A other guy report that... But didn't find exactly why his compute > functions as stop working properly... > > To me it's related to the fact tha if I do : > > Field('mycomputefield', compute=lambda r: r) > > I am not getting all the fields. > > For example: > > db.define_table('test1', > Field('f1','string'), > Field('f2','integer'), > Field('computefield',compute=lambda r: r)) > > Will return only field that appear in form, so if I set f1 to > writable=False, it will not be in form so it will not be available to > compute function... > > I think it for make compute failed silently if some fields are set to > writable or readable = False... But I would return all the field to compute > with a "None" for empty field instead of not returning any key... I really > don't know if it even possible, if it is a bug or something else... > > I work around issue I were having with compute (I would compute a md5 hash > for row so I would have all key/value pairs even if one of those were > empty, but I can't with compute), so I use the new virtual field style > (hope it will stay). > > Here the thread I am refering to : > http://groups.google.com/group/web2py/browse_thread/thread/cd6191f9827a48d5/a367c0e5055bb676?lnk=gst&q=Computed+Fields+broken+by+1.99.2#a367c0e5055bb676 > > > Richard > > On Mon, Dec 19, 2011 at 2:22 PM, Anthony <abasta...@gmail.com> wrote: > >> What do you mean it doesn't return all the fields? >> >> >> On Monday, December 19, 2011 10:47:42 AM UTC-5, Richard wrote: >>> >>> Hello, >>> >>> I try to use compute to generate a record md5_hash on insert and >>> update, but I discover that compute=lambda r: don't return all the >>> db.table fields why? >>> >>> Thanks >>> >>> Richard >>> >>> >