Skip to content

Commit

Permalink
fix: Skip virtual doctypes while renaming (#25473) (#25477)
Browse files Browse the repository at this point in the history
(cherry picked from commit b28db47)

Co-authored-by: Ankush Menat <ankush@frappe.io>
  • Loading branch information
mergify[bot] and ankush committed Mar 15, 2024
1 parent 65f51b6 commit c423223
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions frappe/model/rename_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ def get_link_fields(doctype: str) -> list[dict]:
frappe.flags.link_fields = {}

if doctype not in frappe.flags.link_fields:
virtual_doctypes = frappe.get_all("DocType", {"is_virtual": 1}, pluck="name")

dt = frappe.qb.DocType("DocType")
df = frappe.qb.DocType("DocField")
cf = frappe.qb.DocType("Custom Field")
Expand All @@ -458,15 +460,20 @@ def get_link_fields(doctype: str) -> list[dict]:
custom_fields = (
frappe.qb.from_(cf)
.select(cf.dt.as_("parent"), cf.fieldname, cf_issingle)
.where((cf.options == doctype) & (cf.fieldtype == "Link"))
.where((cf.options == doctype) & (cf.fieldtype == "Link") & (cf.dt.notin(virtual_doctypes)))
.run(as_dict=True)
)

ps_issingle = frappe.qb.from_(dt).select(dt.issingle).where(dt.name == ps.doc_type).as_("issingle")
property_setter_fields = (
frappe.qb.from_(ps)
.select(ps.doc_type.as_("parent"), ps.field_name.as_("fieldname"), ps_issingle)
.where((ps.property == "options") & (ps.value == doctype) & (ps.field_name.notnull()))
.where(
(ps.property == "options")
& (ps.value == doctype)
& (ps.field_name.notnull())
& (ps.doc_type.notin(virtual_doctypes))
)
.run(as_dict=True)
)

Expand Down

0 comments on commit c423223

Please sign in to comment.