From 9689ce520207c773bb82e135c838b613a71a50fe Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Thu, 30 Sep 2021 23:32:46 +0200 Subject: [PATCH] catch invalid config values for enum dropdowns and reset to default --- owrx/form/input/converter.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/owrx/form/input/converter.py b/owrx/form/input/converter.py index 5f9d15b..bf9b5f1 100644 --- a/owrx/form/input/converter.py +++ b/owrx/form/input/converter.py @@ -61,7 +61,14 @@ class EnumConverter(Converter): self.enumCls = enumCls def convert_to_form(self, value): - return None if value is None else self.enumCls(value).name + if value is None: + return None + try: + return self.enumCls(value).name + # if the current value is not part of the enum, this will happen: + except ValueError: + # and this will restore the default + return None def convert_from_form(self, value): return self.enumCls[value].value