diff --git a/frappe/model/rename_doc.py b/frappe/model/rename_doc.py index 5b1f9c3fe0..b9c0f8f10f 100644 --- a/frappe/model/rename_doc.py +++ b/frappe/model/rename_doc.py @@ -478,16 +478,15 @@ def get_link_fields(doctype: str) -> list[dict]: .inner_join(dt) .on(df.parent == dt.name) .select(df.parent, df.fieldname, dt.issingle.as_("issingle")) - .where((df.options == doctype) & (df.fieldtype == "Link")) + .where( + (df.options == doctype) + & (df.fieldtype == "Link") + & (dt.is_virtual == 0) + & (df.is_virtual == 0) + ) ) - if frappe.db.has_column("DocField", "is_virtual"): - standard_fields_query = standard_fields_query.where(df.is_virtual == 0) - - virtual_doctypes = [] - if frappe.db.has_column("DocType", "is_virtual"): - virtual_doctypes = frappe.get_all("DocType", {"is_virtual": 1}, pluck="name") - standard_fields_query = standard_fields_query.where(dt.is_virtual == 0) + virtual_doctypes = frappe.get_all("DocType", {"is_virtual": 1}, pluck="name") standard_fields = standard_fields_query.run(as_dict=True) @@ -495,7 +494,7 @@ 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.is_virtual == 0)) ) if virtual_doctypes: custom_fields = custom_fields.where(cf.dt.notin(virtual_doctypes))