diff --git a/src/caoscrawler/sync_graph.py b/src/caoscrawler/sync_graph.py index b8d4274b416e9861b9f33234cf290f4917d9577f..ff9b7c6fa05eb4fc8b026bb160e81bc2151bc99e 100644 --- a/src/caoscrawler/sync_graph.py +++ b/src/caoscrawler/sync_graph.py @@ -88,7 +88,7 @@ class SyncGraph(): ) = self._create_reference_mapping(self.nodes) self._mark_entities_with_path_or_id() - for node in self.nodes: + for node in list(self.nodes): try: identifiable = self.identifiableAdapter.get_identifiable( node, self.backward_id_referenced_by[node.uuid]) @@ -106,6 +106,8 @@ class SyncGraph(): if node_id is None: node_id = self._get_new_id() node.id = node_id + for el in node.other: + el.id = node_id if node_id in self._id_look_up: self._merge_into(node, self._id_look_up[node.id]) else: @@ -358,8 +360,10 @@ class SyncGraph(): if isinstance(v, SyncNode): forward_references[node.uuid].add(v) backward_references[v.uuid].add(node) - if len([el.name for el in node.registered_identifiable.properties if - el.name == p.name]) > 0: + if (node.registered_identifiable is not None + and len([el.name + for el in node.registered_identifiable.properties if + el.name == p.name]) > 0): forward_id_references[node.uuid].add(v) backward_id_references[v.uuid].add(node) if (v.registered_identifiable is not None and @@ -418,6 +422,9 @@ class SyncGraph(): assert source is not target target.update(source) target.other.append(source) + target.other.extend(source.other) + for el in target.other: + el.id = target.id # update reference mappings for node in self.forward_references.pop(source.uuid): diff --git a/unittests/test_sync_graph.py b/unittests/test_sync_graph.py index 64b70a59008607c225d38c4fdf82e452ff48bbc0..2b39d42e225d39d7bcbecbd8d04cba07bddef976 100644 --- a/unittests/test_sync_graph.py +++ b/unittests/test_sync_graph.py @@ -455,7 +455,7 @@ def test_set_id_of_node(simple_adapter): @patch("caoscrawler.sync_graph.cached_get_entity_by", new=Mock(side_effect=mock_get_entity_by)) -def test_merging(): +def test_merging(simple_adapter): # identifying information can be given at various locations in the hierachical tree # test whether an object is correctly combined for all cases ident_adapter = CaosDBIdentifiableAdapter() @@ -515,6 +515,26 @@ def test_merging(): assert 101 == st.nodes[0].id +def test_something(simple_adapter): + a = db.Record().add_parent("RT3").add_property('a', value=1) + entlist = [ + a, + db.Record().add_parent("RT3").add_property('a', value=1), + db.Record().add_parent("RT3").add_property('a', value=1), + db.Record().add_parent("RT3").add_property('a', value=1), + db.Record().add_parent("RT3").add_property('a', value=1), + db.Record().add_parent("RT4").add_property('RT3', value=a), + db.Record().add_parent("RT3").add_property('a', value=1), + db.Record().add_parent("RT3").add_property('a', value=1)] + st = SyncGraph(entlist, simple_adapter) + assert len(st.nodes) == 2 + assert len(st.unchecked) == 2 + assert 'RT4' == st.nodes[1].parents[0].name + st.set_id_of_node(st.nodes[0], 101) + b_prop = st.nodes[1].properties[0].value + assert b_prop.id == 101 + + def test_sync_node(): # initialization rec = (db.Record(id=101, name='101')