I've solved 1/2 of the problem: as per the documentation, `required` only applies to DB access; instead, I needed to supply appropriate validators via the `requires` parameter.
That still leaves the exception; I can understand it being an odd situation (validation against the DB when no DB IO is requested), and I don't get the exception once the appropriate `requires` parameter is supplied, but it doesn't seem like this should be raising an exception. On Sunday, January 3, 2016 at 9:46:34 PM UTC-5, Scott Hunter wrote: > > If I create a SQLFORM from a table, but avoid DBIO (either by just calling > validate, or calling process(dbio=False).accepted), if a required field is > missing, instead of the form coming back w/ errors, It throws a NOT_IN_DB > exception. > > def request_trial(): > form = SQLFORM(db.t_trial) > if form.process(dbio=False).accepted: > session.flash = "Trial Requested" > redirect( URL(f="index", user_signature=True) ) > return locals() > > > > Here's the traceback: > > Traceback (most recent call last): > File "/Users/scott_mbp/Dropbox/web2py_uki/gluon/restricted.py", > line 227, in restricted > exec ccode in environment > File > "/Users/scott_mbp/Dropbox/web2py_uki/applications/init_bkup/controllers/default.py" > , line 494, in <module> > File "/Users/scott_mbp/Dropbox/web2py_uki/gluon/globals.py", line > 412, in <lambda> > self._caller = lambda f: f() > File > "/Users/scott_mbp/Dropbox/web2py_uki/applications/init_bkup/controllers/default.py" > , line 480, in request_trial > if form.process(dbio=False).accepted: > File "/Users/scott_mbp/Dropbox/web2py_uki/gluon/html.py", line 2304, > in process > self.validate(**kwargs) > File "/Users/scott_mbp/Dropbox/web2py_uki/gluon/html.py", line 2241, > in validate > if self.accepts(**kwargs): > File "/Users/scott_mbp/Dropbox/web2py_uki/gluon/sqlhtml.py", line > 1505, in accepts > **kwargs > File "/Users/scott_mbp/Dropbox/web2py_uki/gluon/html.py", line 2122, > in accepts > status = self._traverse(status, hideerror) > File "/Users/scott_mbp/Dropbox/web2py_uki/gluon/html.py", line 888, > in _traverse > newstatus = c._traverse(status, hideerror) and newstatus > File "/Users/scott_mbp/Dropbox/web2py_uki/gluon/html.py", line 888, > in _traverse > newstatus = c._traverse(status, hideerror) and newstatus > File "/Users/scott_mbp/Dropbox/web2py_uki/gluon/html.py", line 888, > in _traverse > newstatus = c._traverse(status, hideerror) and newstatus > File "/Users/scott_mbp/Dropbox/web2py_uki/gluon/html.py", line 888, > in _traverse > newstatus = c._traverse(status, hideerror) and newstatus > File "/Users/scott_mbp/Dropbox/web2py_uki/gluon/html.py", line 895, > in _traverse > newstatus = self._validate() > File "/Users/scott_mbp/Dropbox/web2py_uki/gluon/html.py", line 1863, > in _validate > raise Exception(msg) > Exception: Validation error, field:f_UKI_ID > <gluon.validators.IS_NOT_IN_DB > object at 0x10e6bfa10> > > > ... and the definition of the field in question: > > Field( 'f_UKI_ID', 'integer', label="UKI ID", unique=True, required= > True ), > > > > (This may be due to the field also being required to be unique; when > unique is not required of any empty fields, I get the behavior described > below.) > > If instead I use a SQLFORM.factory, missing required fields pass > validation; here is the new definition of `form`: > > form = SQLFORM.factory( Field( 'Name', label="Name", required=True ) ) > > > > Has this always been the behavior? If so, can someone explain the > rationale behind it? > > This is using Version 2.13.4-stable+timestamp.2015.12.26.04.59.39 > > - Scott Hunter > -- 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.