Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG?] reparent_from_id_append() does not set new parent for the migrating children that have their own children. #44

Open
digitalcortex opened this issue Feb 12, 2025 · 1 comment

Comments

@digitalcortex
Copy link

digitalcortex commented Feb 12, 2025

Scope: node_mut.reparent_from_id_append(...)
Observation: reparented child that contains own children retains the link to the old parent.
Expected: all reparented children get "parent" link updated to the new parent regardless of whether they have own children.
Library version: ego-tree = "0.10.0"

I'm writing an algorithm that is merging the contents of the multiple consequent matching siblings into one node. In order to transfer children from one node to another node I'm calling reparent_from_id_append() on the future parent and passing sibling's id as an argument.

Example.

Tree before merging:

Heading2 (NodeId(7))
    Text (NodeId(8)): "Self-Managed Cyprus\n\t\t\t\t\t\t\t\t\t\t\tLTD"
Heading2 (NodeId(9))
    Text (NodeId(10)): "from "
    Bold (NodeId(11))
        Text (NodeId(12)): "€ 1070"
    Text (NodeId(13)): "\n\t\t\t\t\t\t\t\t\t\t\tplus VAT"
Heading2 (NodeId(14))
    Link (NodeId(15))
        Text (NodeId(16)): "Order now"

Expected tree after merging:

Heading2 (NodeId(7))
    Text (NodeId(8)): "Self-Managed Cyprus\n\t\t\t\t\t\t\t\t\t\t\tLTD"
    Text (NodeId(10)): "from "
    Bold (NodeId(11))
        Text (NodeId(12)): "€ 1070"
    Text (NodeId(13)): "\n\t\t\t\t\t\t\t\t\t\t\tplus VAT"
    Link (NodeId(15))
        Text (NodeId(16)): "Order now"

In this example I'm having issue with Node 11: it is retaining a reference to the old parent Node 9 while it should be pointing at a new parent Node 7. I verified that by migrated_child.ancestors() method and migrated_child.parent.

It does not seem like an intended behavior because Node 7 starts having Node 11 among its children (as expected) but Node 11 doesn't seem to know about it and still remembers old parent Node 9 (not expected).

Could anyone from maintainers please provide some information on this issue I'm having?

@digitalcortex
Copy link
Author

digitalcortex commented Feb 12, 2025

Using "append_id()" directly for every migrating child of the merged node works well, library updates references to parents well.

So I'm suspecting the issue is really with "reparent_from_id_append()". I only found one test case of reparent_from_id_append in the library and, if Im not mistaken, it does not seem to include the situation I'm describing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant