Merge pull request #31386 from sokumon/orphan-child-table

fix: add check for child doctype if it has a valid parent
This commit is contained in:
Soham Kulkarni 2025-02-25 14:33:20 +05:30 committed by GitHub
commit ce237efd58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -504,6 +504,13 @@ def get_linked_docs(doctype: str, name: str, linkinfo: dict | None = None) -> di
# dynamic link_context
if doctype_fieldname := link_context.get("doctype_fieldname"):
filters.append([linked_doctype, doctype_fieldname, "=", doctype])
# check for child table that no one links to
if linked_doctype_meta.istable:
if not (
frappe.db.exists("DocField", {"options": linked_doctype})
or frappe.db.exists(linked_doctype, {"parenttype": doctype, "parent": name})
):
continue
ret = frappe.get_list(
doctype=linked_doctype, fields=fields, filters=filters, or_filters=or_filters, order_by=None
)