Merge lp:~leonardr/lazr.restful/missing-field-error into lp:lazr.restful

Proposed by Leonard Richardson
Status: Merged
Approved by: Gary Poster
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~leonardr/lazr.restful/missing-field-error
Merge into: lp:lazr.restful
Diff against target: 34 lines (+5/-2)
2 files modified
src/lazr/restful/_resource.py (+4/-1)
src/lazr/restful/example/base/tests/entry.txt (+1/-1)
To merge this branch: bzr merge lp:~leonardr/lazr.restful/missing-field-error
Reviewer Review Type Date Requested Status
Gary Poster code Approve
Review via email: mp+18037@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) wrote :

This branch fixes a small lazr.restful test failure that has been bothering me for about two weeks. I believe the failure was triggered by a new release of zope.schema or some other Zope component, but I haven't gone too deeply into it.

Here's what I think happened: when you tried to set a required field to None, Zope raises a RequiredMissing exception. It used to be that this exception had an empty string associated with it. lazr.restful caught ValidationError, the superclass of RequiredMissing, and substituted the generic string "Validation error" for the empty string.

Then, this new release of zope.schema (or whatever) happened, and now the RequiredMissing exception isn't created with an empty string. It's created with the name of the field that had the error. Since the string isn't empty, lazr.restful leaves it alone and you get the useless error "fieldname: fieldname".

To fix this I explicitly catch the RequiredMissing exception and put in the more useful error message "Missing required value".

102. By Leonard Richardson

Improved the error message.

Revision history for this message
Gary Poster (gary) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lazr/restful/_resource.py'
2--- src/lazr/restful/_resource.py 2010-01-11 18:27:43 +0000
3+++ src/lazr/restful/_resource.py 2010-01-25 20:59:11 +0000
4@@ -66,7 +66,7 @@
5 from zope.publisher.interfaces.http import IHTTPRequest
6 from zope.schema import ValidationError, getFieldsInOrder
7 from zope.schema.interfaces import (
8- ConstraintNotSatisfied, IBytes, IField, IObject)
9+ ConstraintNotSatisfied, IBytes, IField, IObject, RequiredMissing)
10 from zope.security.interfaces import Unauthorized
11 from zope.security.proxy import removeSecurityProxy
12 from zope.security.management import checkPermission
13@@ -1091,6 +1091,9 @@
14 error = "Constraint not satisfied."
15 errors.append("%s: %s" % (repr_name, error))
16 continue
17+ except RequiredMissing, e:
18+ error = "Missing required value."
19+ errors.append("%s: %s" % (repr_name, error))
20 except (ValueError, ValidationError), e:
21 error = str(e)
22 if error == "":
23
24=== modified file 'src/lazr/restful/example/base/tests/entry.txt'
25--- src/lazr/restful/example/base/tests/entry.txt 2009-10-27 17:45:53 +0000
26+++ src/lazr/restful/example/base/tests/entry.txt 2010-01-25 20:59:11 +0000
27@@ -804,7 +804,7 @@
28 ... {'name' : None}, 'PATCH')
29 HTTP/1.1 400 Bad Request
30 ...
31- name: Validation error
32+ name: Missing required value.
33
34 And of course you can't modify attributes that don't exist.
35

Subscribers

People subscribed via source and target branches