Repository: topoteretes/cognee
File: cognee/modules/graph/utils/get_graph_from_model.py (Python)

Code before:
            # DataPoint relationship
            _process_datapoint_field(
                data_point_id,
                field_name,
                edge_datapoint_pairs,
                visited_properties,
                properties_to_visit,
                excluded_properties,
            )

    # Create node for current DataPoint if needed
    if include_root and data_point_id not in added_nodes:
        SimpleDataPointModel = copy_model(
            type(data_point), exclude_fields=list(excluded_properties)
        )
        nodes.append(SimpleDataPointModel(**data_point_properties))
        added_nodes[data_point_id] = True

    # Process all relationships using generator
    for target_datapoint, field_name, edge_metadata in _targets_generator(
        data_point, properties_to_visit
    ):
        relationship_name = _get_relationship_key(field_name, edge_metadata)

        # Create edge if not already added
        edge_key = f"{data_point_id}{target_datapoint.id}{field_name}"
        if edge_key not in added_edges:
            edge_properties = _create_edge_properties(
                data_point.id, target_datapoint.id, relationship_name, edge_metadata
            )
            edges.append((data_point.id, target_datapoint.id, relationship_name, edge_properties))
            added_edges[edge_key] = True

        # Mark property as visited - CRITICAL for preventing infinite loops
        property_key = _generate_property_key(
            data_point_id, relationship_name, str(target_datapoint.id)
        )
        visited_properties[property_key] = True

        # Recursively process target node if not already processed
        if str(target_datapoint.id) in added_nodes:
            continue

        child_nodes, child_edges = await get_graph_from_model(
            target_datapoint,
            include_root=True,
            added_nodes=added_nodes,
            added_edges=added_edges,
            visited_properties=visited_properties,
        )
        nodes.extend(child_nodes)

Review comment (suggestion):
I know you didn't change this, but theoretically this can cause missing visits between:

datapoint_id = 1
target_datapoint_id = 23
field_name='something'

and

datapoint_id = 12
target_datapoint_id=3
field_name='something'


Because they will get the same edge key.

Code after:
            # DataPoint relationship
            _process_datapoint_field(
                data_point_id,
                field_name,
                edge_datapoint_pairs,
                visited_properties,
                properties_to_visit,
                excluded_properties,
            )

    # Create node for current DataPoint if needed
    if include_root and data_point_id not in added_nodes:
        SimpleDataPointModel = copy_model(
            type(data_point), exclude_fields=list(excluded_properties)
        )
        nodes.append(SimpleDataPointModel(**data_point_properties))
        added_nodes[data_point_id] = True

    # Process all relationships using generator
    for target_datapoint, field_name, edge_metadata in _targets_generator(
        data_point, properties_to_visit
    ):
        relationship_name = _get_relationship_key(field_name, edge_metadata)

        # Create edge if not already added
        edge_key = f"{data_point_id}_{target_datapoint.id}_{field_name}"
        if edge_key not in added_edges:
            edge_properties = _create_edge_properties(
                data_point.id, target_datapoint.id, relationship_name, edge_metadata
            )
            edges.append((data_point.id, target_datapoint.id, relationship_name, edge_properties))
            added_edges[edge_key] = True

        # Mark property as visited - CRITICAL for preventing infinite loops
        property_key = _generate_property_key(
            data_point_id, relationship_name, str(target_datapoint.id)
        )
        visited_properties[property_key] = True

        # Recursively process target node if not already processed
        if str(target_datapoint.id) in added_nodes:
            continue

        child_nodes, child_edges = await get_graph_from_model(
            target_datapoint,
            include_root=True,
            added_nodes=added_nodes,
            added_edges=added_edges,
            visited_properties=visited_properties,
        )
        nodes.extend(child_nodes)