Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

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

@carlos-montano-hub

Description

@carlos-montano-hub

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions