tried to build from scratch with minimal code for test before insert 
callback problem :
*1. create new web2py app*
*2. models/db_test.py*
def before_insert_test(f):
    f['field1'] = 'field1'

db.define_table('table0', 
    Field('field0', notnull = True, required = True), 
    Field('field1', notnull = True, required = True) )

db.table0._before_insert.append(before_insert_test)

*3. controllers/install.py*
def index():
    db.table0.insert(field0 = 'field0')

*4. error result*
Traceback (most recent call last):
  File "/Users/MacBookPro/site/web2py/gluon/restricted.py", line 219, in 
restricted
    exec(ccode, environment)
  File 
"/Users/MacBookPro/site/web2py/applications/test/controllers/install.py", 
line 6, in <module>
  File "/Users/MacBookPro/site/web2py/gluon/globals.py", line 406, in 
<lambda>
    self._caller = lambda f: f()
  File 
"/Users/MacBookPro/site/web2py/applications/test/controllers/install.py", 
line 4, in index
    db.table0.insert(field0 = 'field0')
  File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/objects.py", 
line 731, in insert
    row = self._fields_and_values_for_insert(fields)
  File "/Users/MacBookPro/site/web2py/gluon/packages/dal/pydal/objects.py", 
line 709, in _fields_and_values_for_insert
    'Table: missing required field: %s' % name)
RuntimeError: Table: missing required field: field1

*5. temporary solution*
i know there are 2 temporary solutions for this:
1. remove notnull=True and required=True
2. set the value for required value, e.g. field1 during insert

*6. question*
the same code work in previous stable version (2.14.6-stable), is it a 
problem or normal in web2py latest version?

thanks and best regards,
stifan

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to