diff --git a/src/caoscrawler/identifiable_adapters.py b/src/caoscrawler/identifiable_adapters.py index 3aae9353cb4c0cf4d6c264616d770837d87e801e..e877163a648d8508e55e8804cd5dc5f962d50ea5 100644 --- a/src/caoscrawler/identifiable_adapters.py +++ b/src/caoscrawler/identifiable_adapters.py @@ -576,6 +576,11 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter): """Load identifiables defined in a yaml file""" with open(path, "r", encoding="utf-8") as yaml_f: identifiable_data = yaml.safe_load(yaml_f) + self.load_from_yaml_object(identifiable_data) + + def load_from_yaml_object(self, identifiable_data): + """Load identifiables defined in a yaml object. + """ for key, value in identifiable_data.items(): rt = db.RecordType().add_parent(key) diff --git a/unittests/test_sync_graph.py b/unittests/test_sync_graph.py index a7c1539118a4cd87d8c46bf6e18b07b90a90361a..48b88f41578333dfd7dcb7e4c498561fbb9c62cc 100644 --- a/unittests/test_sync_graph.py +++ b/unittests/test_sync_graph.py @@ -651,3 +651,28 @@ def test_set_each_scalar_value(): assert a.properties[0].value == 42 _set_each_scalar_value(a, lambda x: x == 42, lambda x: None) assert a.properties[0].value is None + + +def test_merge_referenced_by(): + """Merging two entities that are referenced by a third entity. + + See also https://gitlab.com/linkahead/linkahead-crawler/-/issues/95 + """ + ident = CaosDBIdentifiableAdapter() + ident.load_from_yaml_object({ + "RT_A": ["name"], + "RT_B": [{"is_referenced_by": "RT_A"}, "my_id"] + }) + + crawled_data: list = [] + references: list = [] + for ii in [0, 1]: + rec = db.Record().add_parent("RT_B").add_property("my_id", value=ii) + references.append(rec) + crawled_data.append(rec) + rec_a = db.Record(name="A").add_parent("RT_A") + rec_a.add_property("my_ref", value=references) + crawled_data.append(rec_a) + + sync_graph = SyncGraph(crawled_data, ident) + assert sync_graph is not None