diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index 06617d1e74d5897e3d5b863938864e185dacb554..6128173976ea42014fe97266da4f706491721747 100644 --- a/src/caosdb/common/models.py +++ b/src/caosdb/common/models.py @@ -992,25 +992,26 @@ def _parse_value(datatype, value): return value # deal with collections - matcher = re.compile(r"^(?P<col>[^<]+)<(?P<dt>[^>]+)>$") - m = matcher.match(datatype) - if m: - col = m.group("col") - dt = m.group("dt") - - if col == "LIST": - ret = list() - else: - return value + if isinstance(datatype, str): + matcher = re.compile(r"^(?P<col>[^<]+)<(?P<dt>[^>]+)>$") + m = matcher.match(datatype) + if m: + col = m.group("col") + dt = m.group("dt") + + if col == "LIST": + ret = list() + else: + return value - if hasattr(value, "__iter__") and not isinstance(value, str): - for v in value: - ret.append(_parse_value(dt, v)) - else: - # put a single value into a list since the datatype says so. - ret.append(_parse_value(dt, value)) + if hasattr(value, "__iter__") and not isinstance(value, str): + for v in value: + ret.append(_parse_value(dt, v)) + else: + # put a single value into a list since the datatype says so. + ret.append(_parse_value(dt, value)) - return ret + return ret # This is for a special case, where the xml parser could not differentiate # between single values and lists with one element. As diff --git a/unittests/test_datatype.py b/unittests/test_datatype.py index ef650ce2e64d45df169dfdc1ab8199f16ae4ef34..e5c457d1f3cd6b693c14e1ee48cb5e54a2d0d4da 100644 --- a/unittests/test_datatype.py +++ b/unittests/test_datatype.py @@ -77,3 +77,14 @@ def test_parsing_of_references(): entity = db.Record(name="bla") assert id(_parse_value(dtype, entity)) == id(entity) + + + dtype = db.RecordType(name="Person") + assert _parse_value(dtype, "Anna Lytik") == "Anna Lytik" + assert _parse_value(None, "Anna Lytik") == "Anna Lytik" + assert _parse_value(dtype, "2345@sdfg") == "2345@sdfg" + assert _parse_value(dtype, "2345") == 2345 + assert _parse_value(dtype, 2345) == 2345 + + entity = db.Record(name="bla") + assert id(_parse_value(dtype, entity)) == id(entity)