diff options
| author | rr- | 2016-08-14 11:41:33 +0200 |
|---|---|---|
| committer | rr- | 2016-08-14 16:43:04 +0200 |
| commit | 86452019a31571e806d695ee2a23c6d8a1d9885b (patch) | |
| tree | 2630789a59a8ea600530e342168081a51db67407 /server/szurubooru/func/util.py | |
| parent | f6f07a35df1720cc1251fe5e331ba9c9744bdf13 (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/szurubooru/func/util.py')
| -rw-r--r-- | server/szurubooru/func/util.py | 7 |
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 |