diff --git a/VERSION b/VERSION index daf05c16..7fd3f52c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.00.1 (2012-08-29 15:42:48) rc4 +Version 2.00.1 (2012-08-29 16:05:38) rc4 diff --git a/gluon/dal.py b/gluon/dal.py index 912fc2ad..22eed09b 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -7673,21 +7673,25 @@ class Table(object): to_compute.append((name,ofield)) # if field is required, check its default value elif not update and not ofield.default is None: - new_fields[name] = (ofield,ofield.default) + value = ofield.default + fields[name] = value + new_fields[name] = (ofield,value) # if this is an update, user the update field instead elif update and not ofield.update is None: - new_fields[name] = (ofield,ofield.update) + value = ofield.update + fields[name] = value + new_fields[name] = (ofield,value) # if the field is still not there but it should, error elif not update and ofield.required: raise RuntimeError, \ 'Table: missing required field: %s' % name # now deal with fields that are supposed to be computed if to_compute: - dummyrow = Row(new_fields) + row = Row(fields) for name,ofield in to_compute: # try compute it try: - new_fields[name] = (ofield,ofield.compute(dummyrow)) + new_fields[name] = (ofield,ofield.compute(row)) except (KeyError, AttributeError): # error sinlently unless field is required! if ofield.required: diff --git a/gluon/tests/test_dal.py b/gluon/tests/test_dal.py index 79e35c26..b60fbe16 100644 --- a/gluon/tests/test_dal.py +++ b/gluon/tests/test_dal.py @@ -515,6 +515,20 @@ class TestVirtualFields(unittest.TestCase): db.t.drop() db.commit() +class TestComputedFields(unittest.TestCase): + + def testRun(self): + db = DAL('sqlite:memory:') + db.define_table('t', + Field('a'), + Field('b',default='x'), + Field('c',compute=lambda r: r.a+r.b)) + db.commit() + id = db.t.insert(a="z") + self.assertEqual(db.t[id].c,'zx') + db.t.drop() + db.commit() + class TestImportExportFields(unittest.TestCase): def testRun(self):