Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NestedSet DocTypes Fail to allow updates on root records #45229

Open
robertoandrade opened this issue Jan 12, 2025 · 0 comments
Open

NestedSet DocTypes Fail to allow updates on root records #45229

robertoandrade opened this issue Jan 12, 2025 · 0 comments
Labels

Comments

@robertoandrade
Copy link

Information about bug

When attempting to update a root record for any of the DocTypes that inherit from NestedSet, I noticed the validate method enforces that the parent field be populated with the reference/name of the root record of that entity if it exists. This prevents one from trying to update one of those records since during validation, the root record will be forced to link to itself, causing an error on a different validation_loop method later on.

This is what causes other issues the community have raised in the past such as #35290, https://discuss.frappe.io/t/bench-update-11-item-cannot-be-added-to-its-own-descendents/36998/9 and #15294

Module

other

Version

both 14 and 15

Installation method

manual install

Relevant log output / Stack trace / Full Error Message.

Document Insert Error
Traceback (most recent call last):
  File "apps/frappe/frappe/desk/page/setup_wizard/setup_wizard.py", line 429, in make_records
    doc.insert(ignore_permissions=True, ignore_if_duplicate=True)
  File "apps/frappe/frappe/model/document.py", line 292, in insert
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1098, in run_post_save_methods
    self.run_method("on_update")
  File "apps/frappe/frappe/model/document.py", line 931, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1283, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1265, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 928, in fn
    return method_object(*args, **kwargs)
  File "apps/erpnext/erpnext/setup/doctype/sales_person/sales_person.py", line 55, in on_update
    super().on_update()
  File "apps/frappe/frappe/utils/nestedset.py", line 263, in on_update
    update_nsm(self)
  File "apps/frappe/frappe/utils/nestedset.py", line 55, in update_nsm
    update_add_node(doc, parent or "", parent_field)
  File "apps/frappe/frappe/utils/nestedset.py", line 77, in update_add_node
    validate_loop(doc.doctype, doc.name, left, right)
  File "apps/frappe/frappe/utils/nestedset.py", line 232, in validate_loop
    frappe.throw(_("Item cannot be added to its own descendents"), NestedSetRecursionError)
  File "apps/frappe/frappe/__init__.py", line 548, in throw
    msgprint(
  File "apps/frappe/frappe/__init__.py", line 509, in msgprint
    _raise_exception()
  File "apps/frappe/frappe/__init__.py", line 455, in _raise_exception
    raise raise_exception(msg)
frappe.utils.nestedset.NestedSetRecursionError: Item cannot be added to its own descendents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant