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:
parent
f6f07a35df
commit
86452019a3
|
@ -26,12 +26,11 @@ def serialize_entity(entity, field_factories, options):
|
||||||
options = field_factories.keys()
|
options = field_factories.keys()
|
||||||
ret = {}
|
ret = {}
|
||||||
for key in options:
|
for key in options:
|
||||||
try:
|
if not key in field_factories:
|
||||||
factory = field_factories[key]
|
|
||||||
ret[key] = factory()
|
|
||||||
except KeyError:
|
|
||||||
raise errors.ValidationError('Invalid key: %r. Valid keys: %r.' % (
|
raise errors.ValidationError('Invalid key: %r. Valid keys: %r.' % (
|
||||||
key, list(sorted(field_factories.keys()))))
|
key, list(sorted(field_factories.keys()))))
|
||||||
|
factory = field_factories[key]
|
||||||
|
ret[key] = factory()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
|
|
Loading…
Reference in New Issue