Re: Getting Error Messages from Compound Validator
Ian Bicking <[email protected]>
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
Joshua T. Burnell wrote:
> Hey, guys-
>
> I've got a schema and I'd like to put a schema inside
> it that would apply to a list. I've been using the
> ForEach.
>
> For example:
>
> class PhoneSchema(Schema):
> number = Number()
> description = UnicodeString()
>
> class UserSchema(Schema):
> name = UnicodeString()
> phone_numbers = ForEach(PhoneSchema)
>
> Make sense? The problem is, if I validate the
> UserSchema and there's any error triggered by any of
> the PhoneSchemas, they come back with a generic
> 'Errors:\n'number':'Invalid number'. However, I'd
> like to know in which repetition the error occurs.
If you unpack the error with unpack_errors, you should see the location.
E.g.:
try:
result = UserScheme().to_python(request)
except Invalid, e:
err = e.unpack_errors()
# then look at err['phone_numbers']
# should have None for correct fields, a string for
# incorrect fields
--
Ian Bicking : [email protected] : http://blog.ianbicking.org
: Write code, do good : http://topp.openplans.org/careers
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/