Can't Modify employee (Item cannot be added to its own descendents)

I Updated to V10, I am having this message when I try to modify employee
Item cannot be added to its own descendents.

Share a screen shot with the steps you are trying to do.


Im just saving the document. I change the photo, or change any field and this is happening. It happens in some employees, Not in all of them. Even if I only click just “save”

1 Like

Can you share your ERPNext and Frappe version along with browser console log?

version ERPNEXT

this is the log in the browser.

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 62, in application
response = frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 22, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 53, in execute_cmd
return, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 939, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/”, line 22, in savedocs
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 256, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 307, in save
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 887, in run_post_save_methods
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 755, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 1024, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 1007, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/”, line 749, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/employee/”, line 60, in on_update
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/hr/doctype/employee/”, line 57, in update_nsm_model
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/”, line 40, in update_nsm
update_add_node(doc, p or ‘’, pf)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/”, line 64, in update_add_node
validate_loop(doc.doctype,, left, right)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/”, line 181, in validate_loop
(“Item cannot be added to its own descendents”), NestedSetRecursionError)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 323, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 309, in msgprint
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 282, in _raise_exception
raise raise_exception(encode(msg))
NestedSetRecursionError: Item cannot be added to its own descendents

Any help on this topic please.!

Same problem here… below is my screenshot when I updated my Employee Data…

I Create an Issue on github

I just bumped into this issue right now with ERPNext v10.1.72

This message resides in this function:

def validate_loop(doctype, name, lft, rgt):
"""check if item not an ancestor (loop)"""
if name in frappe.db.sql_list("""select name from `tab{0}` where lft <= %s and rgt >= %s"""
	 .format(doctype), (lft, rgt)):
	frappe.throw(_("Item cannot be added to its own descendents"), NestedSetRecursionError)

In this file:

And in the case of Employee, I cannot find where it is pulling this message from yet…

I concur that this is the behavior, if you just open the employee, and make no changes at all and click Save, the same behavior occurs. I am checking into this now. It happened after an update to ERPNext v10.1.72

I barely remember how to fix it. but I think that I went to the database and saw the table TabEmployee and the column lft and rgt was at “0”. I just filled with the sequence and it worked.

1 Like

Any update on this? Just encountered the same issue!

Kind regards,

Okay, I think I may have found the cause of the issue. The Employee was reporting to another Employee who had ‘Left’ the organization. Clearing the ‘Reports To’ field seems to have solved the issue

There should be a way for the system to handle this gracefully! An Employee’s status should NOT be allowed to be changed to ‘Left’ if there are other Employees reporting to him/her