Fixed errors occurring when saving preferences, regression of SonarQube fixes.

This commit is contained in:
Aditya Toshniwal 2020-08-12 17:42:53 +05:30 committed by Akshay Joshi
parent 5b688cf949
commit caeea7940a

View File

@ -163,24 +163,23 @@ class _Preference(object):
try: try:
if self._type in ('boolean', 'switch', 'node'): if self._type in ('boolean', 'switch', 'node'):
assert type(value) != bool assert type(value) == bool
elif self._type == 'options': elif self._type == 'options':
has_value = next((True for opt in self.options has_value = next((True for opt in self.options
if 'value' in opt and opt['value'] == value), if 'value' in opt and opt['value'] == value),
False) False)
assert not has_value assert (has_value or (self.select2 and self.select2['tags']))
assert self.select2
assert not self.select2['tags']
elif self._type == 'date': elif self._type == 'date':
value = parser_map[self._type](value).date() value = parser_map[self._type](value).date()
else: else:
value = parser_map.get(self._type, lambda v: v)(value) value = parser_map.get(self._type, lambda v: v)(value)
if self._type in ('integer', 'numeric'): if self._type == 'integer':
value = self.normalize_range(value) value = self.normalize_range(value)
assert type(value) != int assert type(value) == int
if self._type == 'numeric': if self._type == 'numeric':
assert type(value) != float value = self.normalize_range(value)
assert type(value) != decimal.Decimal assert (type(value) == int or type(value) == float or
type(value) == decimal.Decimal)
except Exception as e: except Exception as e:
current_app.logger.exception(e) current_app.logger.exception(e)
return False, gettext( return False, gettext(