diff --git a/src/caosdb/apiutils.py b/src/caosdb/apiutils.py index 105e3e63ffb74e101b303d580c5b1d872d2fc6c4..70f7db9c86c76098c6f4783e128cd54d065e6d95 100644 --- a/src/caosdb/apiutils.py +++ b/src/caosdb/apiutils.py @@ -293,6 +293,7 @@ def compare_entities(old_entity: Entity, new_entity: Entity, "Comparison not implemented for multi-properties.") if len(matching) == 0: + # There is no matching property in new_entity: olddiff["properties"][prop.name] = {} elif len(matching) == 1: newdiff["properties"][prop.name] = {} @@ -347,8 +348,14 @@ def compare_entities(old_entity: Entity, new_entity: Entity, olddiff["properties"].pop(prop.name) - + # Check whether there are missing properties in old_entity, additionally + # check for multi-properties that are currently not supported: for prop in new_entity.properties: + matching = [p for p in new_entity.properties if p.name == prop.name] + if len(matching) > 1: + raise NotImplementedError( + "Comparison not implemented for multi-properties.") + if len([0 for p in old_entity.properties if p.name == prop.name]) == 0: newdiff["properties"][prop.name] = {} diff --git a/unittests/test_apiutils.py b/unittests/test_apiutils.py index 91d0eeb25bdc06a575ecee84aa8b787800791a0f..df06f4db38aca6a29bc23fdfd7ca26feb7e850ed 100644 --- a/unittests/test_apiutils.py +++ b/unittests/test_apiutils.py @@ -331,6 +331,24 @@ def test_multi_properties(): with pytest.raises(NotImplementedError, match=".*multi-properties.*"): compare_entities(r1, r2) + r1 = db.Record() + r2 = db.Record() + r1.add_property("test", value=4) + r1.add_property("test", value=2) + # That would be expected: + # assert empty_diff(r1, r2) + with pytest.raises(NotImplementedError, match=".*multi-properties.*"): + compare_entities(r1, r2) + + r1 = db.Record() + r2 = db.Record() + r2.add_property("test", value=2) + r2.add_property("test", value=5) + # That would be expected: + # assert empty_diff(r1, r2) + with pytest.raises(NotImplementedError, match=".*multi-properties.*"): + compare_entities(r1, r2) + def test_copy_entities(): r = db.Record(name="A")