{"action":"closed","issue":{"url":"https://api.github.com/repos/django-mptt/django-mptt/issues/672","repository_url":"https://api.github.com/repos/django-mptt/django-mptt","labels_url":"https://api.github.com/repos/django-mptt/django-mptt/issues/672/labels{/name}","comments_url":"https://api.github.com/repos/django-mptt/django-mptt/issues/672/comments","events_url":"https://api.github.com/repos/django-mptt/django-mptt/issues/672/events","html_url":"https://github.com/django-mptt/django-mptt/issues/672","id":356652041,"node_id":"MDU6SXNzdWUzNTY2NTIwNDE=","number":672,"title":"Incorrect lft/rght of root nodes on rebuild/insert","user":{"login":"radiophysicist","id":1335647,"node_id":"MDQ6VXNlcjEzMzU2NDc=","avatar_url":"https://avatars1.githubusercontent.com/u/1335647?v=4","gravatar_id":"","url":"https://api.github.com/users/radiophysicist","html_url":"https://github.com/radiophysicist","followers_url":"https://api.github.com/users/radiophysicist/followers","following_url":"https://api.github.com/users/radiophysicist/following{/other_user}","gists_url":"https://api.github.com/users/radiophysicist/gists{/gist_id}","starred_url":"https://api.github.com/users/radiophysicist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/radiophysicist/subscriptions","organizations_url":"https://api.github.com/users/radiophysicist/orgs","repos_url":"https://api.github.com/users/radiophysicist/repos","events_url":"https://api.github.com/users/radiophysicist/events{/privacy}","received_events_url":"https://api.github.com/users/radiophysicist/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-09-04T04:50:29Z","updated_at":"2018-09-04T05:42:09Z","closed_at":"2018-09-04T05:42:09Z","author_association":"NONE","body":"I've added MPTT to the existing model. After running rebuild (via admin action I also added) I can see that all root nodes have lft equal to 1. This results in incorrect tree queries like getting node descendants etc.\r\n\r\nFor example:\r\n```\r\n# select id, designator, parent_id, lft, rght, tree_id, level from products_productgroup where parent_id is null;\r\n id  |          designator          | parent_id | lft | rght | tree_id | level \r\n-----+------------------------------+-----------+-----+------+---------+-------\r\n   1 | Product group #1             |           |   1 |    6 |       1 |     0\r\n   4 | Nitrogen Fertilizers         |           |   1 |    2 |       2 |     0\r\n   5 | Phosphate Fertilizers        |           |   1 |    2 |       3 |     0\r\n   6 | Potassium Fertilizers        |           |   1 |    2 |       4 |     0\r\n   7 | Binary Compound Fertilizers  |           |   1 |    2 |       5 |     0\r\n   8 | Ternary Compound Fertilizers |           |   1 |    2 |       6 |     0\r\n   9 | Amendments                   |           |   1 |    2 |       7 |     0\r\n  10 | Mixture                      |           |   1 |    2 |       8 |     0\r\n 434 | TEST                         |           |   1 |    2 |      10 |     0\r\n  11 | Seeds                        |           |   1 |  846 |       9 |     0\r\n(10 rows)\r\n```\r\n\r\nIt is also true for newly added nodes (like id=434 in the listing above).\r\nLooking at the code it seems that lft=1 for the root nodes is hardcoded in `TreeManager.rebuild()` (https://github.com/django-mptt/django-mptt/blob/f17e93e8349d0eda2ef30261289e116eec61f1aa/mptt/managers.py#L653).\r\n\r\nIs it assumed to be correct behaviour? Is there any way to obtain unique lft values for root node elements?\r\n\r\nP.S.\r\ndjango version 2.0.1, django-mptt version 0.9.1"}}
{"actor":{"display_login":"radiophysicist"}}