uralbash / sqlalchemy_mptt

SQLAlchemy nested sets mixin (MPTT)
http://sqlalchemy-mptt.readthedocs.io
MIT License
196 stars 32 forks source link

Updating nodes without an existing parent does not work #71

Open shiviscs opened 4 years ago

shiviscs commented 4 years ago

There appears to be an issue when adding a parent ID to an existing node that doesn’t already have a parent ID, in the same tree. The use case is like so:

node_1 # a node that has no parent, but valid left and right values. so it is a root and a leaf
parent_node # another node that we will be making into the parent node for node_1

node_1.parent_id = parent_node.id
session.add(node_1)
session.commit()

The tree_id is the same for both nodes. Once this is done, node_1 does not get updated with the new parent ID. The parent ID still remains null, and the left and right values are the same.

This issue happens only in nodes where they don’t have an existing parent_id. So, whenever we try to update such nodes by giving them a parent_id, the update fails and the nodes remain the same.