Skip to content

Commit 4573029

Browse files
committed
Add error handling. @Apiver was being processed as a search
field. Change code to ignore since I can't delete the key from FieldStorage. Trap KeyError and report error to client if a filter field name is invalid. Make error more descriptive in another place where field is invalid.
1 parent ef3cd06 commit 4573029

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

roundup/rest.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,16 @@ def get_collection(self, class_name, input):
601601
except KeyError as err:
602602
raise UsageError("Failed to find property '%s' "
603603
"for class %s."%(i, class_name))
604-
605-
604+
elif key.startswith("@"):
605+
# ignore any unsupported/previously handled control key
606+
# like @apiver
607+
pass
606608
else: # serve the filter purpose
607-
prop = class_obj.getprops()[key]
609+
try:
610+
prop = class_obj.getprops()[key]
611+
except KeyError:
612+
raise UsageError("Field %s is not valid for %s class."%(
613+
key, class_name))
608614
# We drop properties without search permission silently
609615
# This reflects the current behavior of other roundup
610616
# interfaces
@@ -720,7 +726,7 @@ def get_element(self, class_name, item_id, input):
720726
try:
721727
k, v = item_id.split('=', 1)
722728
if k != keyprop:
723-
raise UsageError ("Not key property")
729+
raise UsageError ("Field %s is not key property"%k)
724730
except ValueError:
725731
v = item_id
726732
pass
@@ -1546,6 +1552,11 @@ def dispatch(self, method, uri, input):
15461552
"for supported versions."%(
15471553
input['@apiver'].value))
15481554
output = self.error_obj(400, msg)
1555+
# sadly del doesn't work on FieldStorage which can be the type of
1556+
# input. So I have to ignore keys starting with @ at other
1557+
# places in the code.
1558+
# else:
1559+
# del(input['@apiver'])
15491560

15501561
# FIXME: do we need to raise an error if client did not specify
15511562
# version? This may be a good thing to require. Note that:

0 commit comments

Comments
 (0)