diff --git a/gluon/dal.py b/gluon/dal.py index 14fc11f6..c5d1d09a 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -8542,10 +8542,12 @@ class Table(object): # try compute it try: new_fields[name] = (ofield,ofield.compute(row)) + __,fields[name] = new_fields[name] #the value is the second element of the tuple + row = Row(fields) #allow later compute fields to refer to this value except (KeyError, AttributeError): - # error sinlently unless field is required! + # error silently unless field is required! if ofield.required: - raise SyntaxError('unable to comput field: %s' % name) + raise SyntaxError('unable to compute field: %s' % name) return new_fields.values() def _attempt_upload(self, fields): diff --git a/gluon/tests/test_dal.py b/gluon/tests/test_dal.py index f4423b54..ab444958 100644 --- a/gluon/tests/test_dal.py +++ b/gluon/tests/test_dal.py @@ -599,6 +599,19 @@ class TestComputedFields(unittest.TestCase): self.assertEqual(db.tt[id].cc,'zx') db.tt.drop() db.commit() + + # test checking that a compute field can refer to earlier-defined computed fields + db.define_table('tt', + Field('aa'), + Field('bb',default='x'), + Field('cc',compute=lambda r: r.aa+r.bb), + Field('dd',compute=lambda r: r.bb + r.cc)) + db.commit() + id = db.tt.insert(aa="z") + self.assertEqual(db.tt[id].dd,'xzx') + db.tt.drop() + db.commit() + class TestCommonFilters(unittest.TestCase):