server/util: improve catching bad field names

KeyError could catch exceptions that happened inside the serializer
routine and mistakenly report them as an error with user input.
This commit is contained in:
rr- 2016-08-14 11:41:33 +02:00
parent f6f07a35df
commit 86452019a3

View file

@ -26,12 +26,11 @@ def serialize_entity(entity, field_factories, options):
options = field_factories.keys()
ret = {}
for key in options:
try:
factory = field_factories[key]
ret[key] = factory()
except KeyError:
if not key in field_factories:
raise errors.ValidationError('Invalid key: %r. Valid keys: %r.' % (
key, list(sorted(field_factories.keys()))))
factory = field_factories[key]
ret[key] = factory()
return ret
@contextmanager