caesar0301/treelib

Modifying a node's identifier with the . and = operator breaks the tree

carlos-montano-hub opened this issue · 0 comments

making use of the . and = in order to modify a node's identifier causes the node to disappear

Ex:

tree["old_identifier"].identifier = "new_identifier "

the code I used to reproduce the issue:

from treelib import Node, Tree

def create_tree():
    tree = Tree()
    tree.create_node("root" , "root")
    for i in range(2):
        id = str(i*100)
        tree.create_node(id, id , parent = "root")
        for j in range(1, 3):
            id = str(i) + str(j*10)
            tree.create_node(id, id , parent = str(i *100))
            for k in range(1, 3):
                id = str(i) + str(j) + str(k)
                tree.create_node(id, id , parent = str(i) + str(j*10))
    tree.show()
    return tree

def break_tree(tree):
    tree["020"].identifier = "030"
    tree.show()

tree = create_tree()
break_tree(tree)

this outputs:

root
├── 0
│   ├── 010
│   │   ├── 011
│   │   └── 012
│   └── 020
│       ├── 021
│       └── 022
└── 100
    ├── 110
    │   ├── 111
    │   └── 112
    └── 120
        ├── 121
        └── 122

Tree is empty
root
├── 0
│   ├── 010
│   │   ├── 011
│   │   └── 012

if you don’t mind I can work on this and please let me know if you have any feedback