I just tested this on v1.97.1 , and confirm that from the shell the
record doesn't appear to be updated even after a db.commit(). However,
using appadmin to check the database, the records were actually are
updated.

But if do it like this:
for i in db(db.item.id>0).select(): i.quantity, i.unit_price,
i.total_price

instead of like:
items =db(db.item.id>0).select()
for i in items: i.quantity, i.unit_price, i.total_price

You will see the record values are immediately updated.

So, I think this is a bug unless I'm very much mistaken.



On Jul 15, 12:17 pm, guruyaya <guruy...@gmail.com> wrote:
> >>> db.commit()
> >>> db(db.item.id == 1).select()[0].total_price
> '9.95'
> >>> db(db.item.id == 1).select()[0]
>
> <Row {'total_price': '9.95', 'update_record': <function <lambda> at
> 0x17f1758>, 'unit_price': 3.0, 'id': 1, 'delete_record': <function
> <lambda> at 0x17f17d0>, 'quantity': 5}>
>
> On Jul 15, 12:54 am, niknok <nikolai...@gmail.com> wrote:
>
>
>
>
>
>
>
> > You're checking it from the shell. Do a db.commit() before checking
> > for total_price.
>
> > On Jul 15, 3:37 am, guruyaya <guruy...@gmail.com> wrote:
>
> > > This is run on a web2py shell:
>
> > > >>> db.define_table('item',
>
> > > ...         Field('unit_price','double'),
> > > ...         Field('quantity','integer'),
> > > ...         Field('total_price',
> > > ...             compute=lambda r: r['unit_price']*r['quantity']))
> > > .
> > > .
> > > .
>
> > > >>> r = db.item.insert(unit_price=1.99, quantity=5)
> > > >>> r.total_price
> > > '9.95'
> > > >>> db(db.item.id == 1).select()[0]
>
> > > <Row {'total_price': '9.95', 'update_record': <function <lambda> at
> > > 0x17f10c8>, 'unit_price': 1.99, 'id': 1, 'delete_record': <function
> > > <lambda> at 0x17f1230>, 'quantity': 5}>
>
> > > Till now, all is good.
>
> > > >>> db(db.item.id == 1).update(unit_price = 3)
> > > 1
> > > >>> db(db.item.id == 1).select()[0].total_price
> > > '9.95'
> > > >>> db(db.item.id == 1).select()[0].unit_price
>
> > > 3.0
>
> > > The web2py book said that
> > > """ When a new record is modified, including both insertions and
> > > *updates*, if a value for the field is not provided, web2py tries to
> > > compute from the other field values using the compute function """
>
> > > How come? shouldn't the compute field be recalculated?
>
> > > Now

Reply via email to