diff --git a/secop/datatypes.py b/secop/datatypes.py index 3f5f3df..220a3a9 100644 --- a/secop/datatypes.py +++ b/secop/datatypes.py @@ -760,7 +760,7 @@ class ArrayOf(DataType): def __call__(self, value): """validate an external representation to an internal one""" - if isinstance(value, (tuple, list)): + try: # check number of elements if self.minlen is not None and len(value) < self.minlen: raise BadValueError( @@ -771,8 +771,9 @@ class ArrayOf(DataType): 'Array too big, holds at most %d elements!' % self.minlen) # apply subtype valiation to all elements and return as list return tuple(self.members(elem) for elem in value) - raise BadValueError( - 'Can not convert %s to ArrayOf DataType!' % repr(value)) + except TypeError: + raise BadValueError('%s can not be converted to ArrayOf DataType!' + % type(value).__name__) from None def export_value(self, value): """returns a python object fit for serialisation""" diff --git a/secop/modules.py b/secop/modules.py index ae3ea85..3806302 100644 --- a/secop/modules.py +++ b/secop/modules.py @@ -509,10 +509,11 @@ class Module(HasAccessibles): # TODO: remove readerror 'property' and replace value with exception pobj = self.parameters[pname] timestamp = timestamp or time.time() - changed = pobj.value != value try: + value = pobj.datatype(value) + changed = pobj.value != value # store the value even in case of error - pobj.value = pobj.datatype(value) + pobj.value = value except Exception as e: if isinstance(e, DiscouragedConversion): if DiscouragedConversion.log_message: