Merging an entity with properties with missing datatype leads to Exception
In [1]: import caosdb as db
In [2]: from caosdb.apiutils import merge_entities
In [3]: merge_entities(db.Record().add_property("a", 5, datatype="B"), db.Record().add_property("a", [1,2]),force=True)
...:
WARNING:root:This function is currently experimental and insufficiently tested. Use with care.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File ~/CaosDB/caosdb-pylib/src/caosdb/common/models.py:1379, in _parse_value(datatype, value)
1378 try:
-> 1379 return int(value)
1380 except ValueError:
1381 # reference via name
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
During handling of the above exception, another exception occurred:
ServerConfigurationException Traceback (most recent call last)
Cell In [3], line 1
----> 1 merge_entities(db.Record().add_property("a", 5, datatype="B"), db.Record().add_property("a", [1,2]),force=True)
File ~/CaosDB/caosdb-pylib/src/caosdb/apiutils.py:433, in merge_entities(entity_a, entity_b, merge_references_with_empty_diffs, force)
430 setattr(entity_a.get_property(key), attribute,
431 diff_r2["properties"][key][attribute])
432 elif force:
--> 433 setattr(entity_a.get_property(key), attribute,
434 diff_r2["properties"][key][attribute])
435 else:
436 raise RuntimeError(
437 f"Merge conflict:\nEntity a ({entity_a.id}, {entity_a.name}) "
438 f"has a Property '{key}' with {attribute}="
(...)
441 f"has a Property '{key}' with {attribute}="
442 f"{diff_r1['properties'][key][attribute]}")
File ~/CaosDB/caosdb-pylib/src/caosdb/common/models.py:277, in Entity.value(self, new_value)
275 @value.setter
276 def value(self, new_value):
--> 277 self.__value = _parse_value(self.datatype, new_value)
File ~/CaosDB/caosdb-pylib/src/caosdb/common/models.py:1387, in _parse_value(datatype, value)
1384 except TypeError:
1385 # deal with invalid XML: List of values without appropriate datatype
1386 if isinstance(value, list):
-> 1387 raise ServerConfigurationException(
1388 "The server sent an invalid XML: List valued properties must be announced by "
1389 "the datatype.\n" + f"Datatype: {datatype}\nvalue: {value}")
ServerConfigurationException: The server sent an invalid XML: List valued properties must be announced by the datatype.
Datatype: B
value: [1, 2]