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
=== modified file 'src/lazr/restful/_resource.py'
--- src/lazr/restful/_resource.py 2010-01-11 18:27:43 +0000
+++ src/lazr/restful/_resource.py 2010-01-25 20:59:11 +0000
@@ -66,7 +66,7 @@
66from zope.publisher.interfaces.http import IHTTPRequest66from zope.publisher.interfaces.http import IHTTPRequest
67from zope.schema import ValidationError, getFieldsInOrder67from zope.schema import ValidationError, getFieldsInOrder
68from zope.schema.interfaces import (68from zope.schema.interfaces import (
69 ConstraintNotSatisfied, IBytes, IField, IObject)69 ConstraintNotSatisfied, IBytes, IField, IObject, RequiredMissing)
70from zope.security.interfaces import Unauthorized70from zope.security.interfaces import Unauthorized
71from zope.security.proxy import removeSecurityProxy71from zope.security.proxy import removeSecurityProxy
72from zope.security.management import checkPermission72from zope.security.management import checkPermission
@@ -1091,6 +1091,9 @@
1091 error = "Constraint not satisfied."1091 error = "Constraint not satisfied."
1092 errors.append("%s: %s" % (repr_name, error))1092 errors.append("%s: %s" % (repr_name, error))
1093 continue1093 continue
1094 except RequiredMissing, e:
1095 error = "Missing required value."
1096 errors.append("%s: %s" % (repr_name, error))
1094 except (ValueError, ValidationError), e:1097 except (ValueError, ValidationError), e:
1095 error = str(e)1098 error = str(e)
1096 if error == "":1099 if error == "":
10971100
=== modified file 'src/lazr/restful/example/base/tests/entry.txt'
--- src/lazr/restful/example/base/tests/entry.txt 2009-10-27 17:45:53 +0000
+++ src/lazr/restful/example/base/tests/entry.txt 2010-01-25 20:59:11 +0000
@@ -804,7 +804,7 @@
804 ... {'name' : None}, 'PATCH')804 ... {'name' : None}, 'PATCH')
805 HTTP/1.1 400 Bad Request805 HTTP/1.1 400 Bad Request
806 ...806 ...
807 name: Validation error807 name: Missing required value.
808808
809And of course you can't modify attributes that don't exist.809And of course you can't modify attributes that don't exist.
810810

Subscribers

People subscribed via source and target branches