On Wednesday, May 31, 2017 at 5:39:11 AM UTC-4, T.R.Rajkumar wrote: > > When I do SQLFORM.grid(db.amc_master) without setting any of the > readable/writable attributes the grid edit works fine. I am able to edit > and the form submits without errors. > Even with specifying the fields list grid edit works fine as the edit from > has all the fields of the table. > But when I set the readable/writable attributes to filter the fields in > edit form the the error 42000 listed above occurs. >
I see the problem. By default, the "id" field is actually set to writable=True. It is excluded from SQLFORM database writes not because of its "writable" attribute but because the SQLFORM.accepts() code explicitly excludes the "id" field. However, the code at this line <https://github.com/web2py/web2py/blob/8a741023d8a2631a0a33dc47ee08f73e71018efc/gluon/sqlhtml.py#L1832> ends up including fields that are in the record by have writable=False. So, because your code sets writable=False for all fields except the three special fields you have identified, the "id" field ends up getting writable=False, which forces it to be included in the database update. To fix this, the following should work: [setattr(f, 'writable', False) for f in db.amc_master if f.name not in ['id', 'amcdesc', 'amcmod', 'complndays']] Anthony -- 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.