diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ca5f692e8c9ca1a89d2b48a23ba4ad017711234..3a0d6cc5339fc1db13358a02e0f80be17ccef848 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 of a RecordType. This is fixed now. * #52 `XLSimporter.read_xls` throwed a wrong error when reading from a file with a wrong ending. Now, a `DataInconsistencyError` is raised instead of a ValueError. +* List properties are no longer updated unnecessarily by the crawler. ### Security ### diff --git a/src/caosadvancedtools/cfood.py b/src/caosadvancedtools/cfood.py index 48b423e01894220d2bd31dab5784932d601f9f62..c818792c79440dc1fcc78f3c0b1ed1b9bd215cb8 100644 --- a/src/caosadvancedtools/cfood.py +++ b/src/caosadvancedtools/cfood.py @@ -47,6 +47,7 @@ from abc import ABCMeta, abstractmethod from datetime import datetime import caosdb as db +from caosdb.common.models import Entity from caosdb.exceptions import (BadQueryError, EmptyUniqueQueryError, QueryNotUniqueError, TransactionError) @@ -662,12 +663,18 @@ def assure_has_property(entity, name, value, to_be_updated=None, if isinstance(value, db.Entity): value = value.id + if isinstance(value, list): + value = [i.id if isinstance(i, db.Entity) else i for i in value] + for el in possible_properties: tmp_value = el.value if isinstance(tmp_value, db.Entity): tmp_value = el.value.id + if isinstance(tmp_value, list): + tmp_value = [i.id if isinstance(i, db.Entity) else i for i in tmp_value] + if tmp_value == value: contained = True diff --git a/unittests/test_cfood.py b/unittests/test_cfood.py index ab5cb11e9dc89faf26527d72e64459cae73b1d88..f5125166106c4bace21121d58a025886f9b132b9 100644 --- a/unittests/test_cfood.py +++ b/unittests/test_cfood.py @@ -190,6 +190,35 @@ class InsertionTest(unittest.TestCase): value=new_int, to_be_updated=to_be_updated) assert to_be_updated[0] is entity + """Test properties with lists""" + rec1 = db.Record(id=12345) + rec1.add_property("Exp", value=[98765], datatype=db.LIST("Exp")) + rec2 = db.Record(id=98765) + update = [] + # compare Entity with id + assure_has_property(rec1, "Exp", [rec2], to_be_updated=update) + assert len(update) == 0 + update = [] + # compare id with id + assure_has_property(rec1, "Exp", [98765], to_be_updated=update) + assert len(update) == 0 + update = [] + # compare id with different list of ids + assure_has_property(rec1, "Exp2", [98765, 444, 555], + to_be_updated=update) + assert len(update) == 1 + + rec = db.Record(id=666666) + rec3 = db.Record(id=777777) + rec.add_property("Exp", value=[888888, rec3], datatype=db.LIST("Exp")) + rec2 = db.Record(id=888888) + update = [] + # compare id and Entity with id and Entity + # i.e. check that conversion from Entity to id works in both + # directions. + assure_has_property(rec, "Exp", [rec2, 777777], to_be_updated=update) + assert len(update) == 0 + def test_property_is(self): """Test properties with string, int, float, and Boolean values""" entity = db.Record()