aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorrr-2016-08-14 11:41:33 +0200
committerrr-2016-08-14 16:43:04 +0200
commit86452019a31571e806d695ee2a23c6d8a1d9885b (patch)
tree2630789a59a8ea600530e342168081a51db67407 /server
parentf6f07a35df1720cc1251fe5e331ba9c9744bdf13 (diff)
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.
Diffstat (limited to 'server')
-rw-r--r--server/szurubooru/func/util.py7
1 files changed, 3 insertions, 4 deletions
diff --git a/server/szurubooru/func/util.py b/server/szurubooru/func/util.py
index f1e8f8f..bbc3bd2 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

© 2015 - 2026 Jakob L. Kreuze