A computed field must be given actual values with which to compute, as the final value is computed by web2py and then inserted into the DB. Your second example uses expressions to express the values to be inserted in the score and created_on fields. However, these expressions will ultimately be evaluated and converted to values by the database itself, so they are never available to web2py for calculation of the computed field. Something like your first approach is necessary if you want to update a computed field.
Anthony On Thursday, July 17, 2014 2:58:44 PM UTC-4, Leonel Câmara wrote: > > If I do this my computed field (that depends on score and created on) is > updated correctly: > > def some_other_table_after_insert(f, id): > record = db.table_with_computed_field[f['ref']] > new_score = record.score + f['score'] > record.update_record(score=new_score, created_on=record.created_on) > > While if I do this, it doesn't work, and I can see that my compute > function is getting Expressions where it should be getting values: > > def some_other_table_after_insert(f, id): > db(db.table_with_computed_field.id == > f['ref']).update(score=db.table_with_computed_field.score + f['score'], > created_on=db.table_with_computed_field.created_on) > > Isn't this a bug? Shouldn't the Expressions have been calculated before > getting to the compute function? > > I only noticed because my compute was silently not doing anything and I > had to use the traceback module to find what was going on: > > AttributeError: 'Expression' object has no attribute 'days' > > Clearly caused by the created_on being an Expression instead of the > datetime it should be. > -- 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 the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

