diff --git a/src/linkahead/common/models.py b/src/linkahead/common/models.py index 8b8141bea1a3dc5dba28257136fe03fdea2f6ba0..0384514325a7866faf192beed5502311758afbe8 100644 --- a/src/linkahead/common/models.py +++ b/src/linkahead/common/models.py @@ -1736,37 +1736,40 @@ def _parse_value(datatype, value): ret.append(_parse_value(dt, value)) return ret + else: + raise NotImplementedError("") # This is for a special case, where the xml parser could not differentiate # between single values and lists with one element. As if hasattr(value, "__len__") and len(value) == 1: return _parse_value(datatype, value[0]) + if isinstance(value, str): # TODO: this is bad. When no datatype is given and we find a str value, we just assume it is an ID and might convert it to int. This might result in negative ints. + if "@" in value: + # probably this is a versioned reference + return value + else: + # for unversioned references + try: + return int(value) + except ValueError: + # reference via name + + return value + except TypeError as te: + # deal with invalid XML: List of values without appropriate datatype + if isinstance(value, list): + raise TypeError( + "Invalid datatype: List valued properties must be announced by " + "the datatype.\n" + f"Datatype: {datatype}\nvalue: {value}") + else: + # Everything else that's not related to wrong list assignments + raise te + # deal with references if isinstance(value, Entity): return value - - if isinstance(value, str) and "@" in value: - # probably this is a versioned reference - - return str(value) - else: - # for unversioned references - try: - return int(value) - except ValueError: - # reference via name - - return str(value) - except TypeError as te: - # deal with invalid XML: List of values without appropriate datatype - if isinstance(value, list): - raise TypeError( - "Invalid datatype: List valued properties must be announced by " - "the datatype.\n" + f"Datatype: {datatype}\nvalue: {value}") - else: - # Everything else that's not related to wrong list assignments - raise te + raise RuntimeError("This should not be reached") def _log_request(request, xml_body=None):