From 86452019a31571e806d695ee2a23c6d8a1d9885b Mon Sep 17 00:00:00 2001 From: rr- Date: Sun, 14 Aug 2016 11:41:33 +0200 Subject: [PATCH] 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. --- server/szurubooru/func/util.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server/szurubooru/func/util.py b/server/szurubooru/func/util.py index f1e8f8fe..bbc3bd27 100644 --- a/server/szurubooru/func/util.py +++ b/server/szurubooru/func/util.py @@ -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