Yes, it's a bug:
*validate_and_insert* calls *_validate_fields* that fills fields with
default values (all table fields!), so for 'y' it's *None *
from book:
" *if a value for the field is not provided*, web2py tries to compute from
the other field values using the compute function"
but it's provided and set to* None* by *_validate_fields!*
On Thursday, October 6, 2016 at 3:41:12 PM UTC+3, Yang wrote:
>
> OK, I packaged it.
>
> model/test.py
> db.define_table('test',
> Field('x', 'float'),
> Field('y', 'float', compute=lambda r: r['x'] * 2))
>
> controller/default.py
> def index():
> db.test.validate_and_insert(x=1)
> db.test.insert(x=1)
> result_validated = db.test(1)
> result_insert = db.test(2)
> return locals()
>
> views/default/index.html
> {{=result_validated}}
> {{=result_insert}}
>
> The output:
> <Row {'x': 1.0, 'id': 1L, 'y': None}> <Row {'x': 1.0, 'id': 2L, 'y': 2.0}>
>
> Thanks!
>
>
>
--
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.