how do you specify the validators for your required fields ?
On Monday, September 9, 2013 5:09:04 AM UTC+2, Christopher Morlier wrote:
>
> Hello,
>
> I am implementing a RESTful API and have the following code in my POST
> handler:
>
> ret = db.recording.validate_and_insert(**fixed_fields)
> if ret.errors:
> raise HTTP(400, 'Validation failed: ' + str(ret.errors))
>
> url = URL('api', args=('recording',ret.id))
> response.headers['Location'] = url
> response.status = 201
> return dict(link=A('Recording ', ret.id, _href=url))
>
> On success, things work as expected. However, if I omit a required field,
> none of my code after validate_and_insert() is called. The client receives
> a HTTP 200 response as if all is well, albeit with an appropriate text
> description of the error.
>
> This is not how validate_and_insert() is described in chapter 6 of the
> book. Is there a reason it is different?
>
> As a work around I added a try-except block around the
> validate_and_insert() call, expecting an HTTP exception, but discovered it
> is actually a RuntimeError exception.
> Is this the recommended work around or is there a better solution?
>
> I browsed through the code, but it isn't clear to me where the exception
> is thrown. However, I believe I noticed two typos in the
> "validate_and_insert, validate_and_update" section:"ret.error" should be
> "ret.errors" and "res.updated" should be "ret.updated".
>
> BTW, I am running 2.5.1-stable+timestamp.2013.06.06.15.39.19 on
> Apache/2.2.16 (Debian)
>
> Thanks for your help,
> Chris
>
--
---
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/groups/opt_out.