Mercurial > p > roundup > code
diff roundup/rest.py @ 5691:dbf422a8cff7
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.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 05 Apr 2019 19:35:32 -0400 |
| parents | 4aae822e2cb4 |
| children | fabb12ba9466 |
line wrap: on
line diff
--- a/roundup/rest.py Wed Apr 03 07:04:29 2019 -0400 +++ b/roundup/rest.py Fri Apr 05 19:35:32 2019 -0400 @@ -601,10 +601,16 @@ except KeyError as err: raise UsageError("Failed to find property '%s' " "for class %s."%(i, class_name)) - - + elif key.startswith("@"): + # ignore any unsupported/previously handled control key + # like @apiver + pass else: # serve the filter purpose - prop = class_obj.getprops()[key] + try: + prop = class_obj.getprops()[key] + except KeyError: + raise UsageError("Field %s is not valid for %s class."%( + key, class_name)) # We drop properties without search permission silently # This reflects the current behavior of other roundup # interfaces @@ -720,7 +726,7 @@ try: k, v = item_id.split('=', 1) if k != keyprop: - raise UsageError ("Not key property") + raise UsageError ("Field %s is not key property"%k) except ValueError: v = item_id pass @@ -1546,6 +1552,11 @@ "for supported versions."%( input['@apiver'].value)) output = self.error_obj(400, msg) + # sadly del doesn't work on FieldStorage which can be the type of + # input. So I have to ignore keys starting with @ at other + # places in the code. + # else: + # del(input['@apiver']) # FIXME: do we need to raise an error if client did not specify # version? This may be a good thing to require. Note that:
