From 224ab37924030b3f13d383c63a6c34d017865439 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 20 Jan 2023 23:58:57 +0530 Subject: [PATCH 1/2] fix: Dont apply non-standard perms in migrate ref: agent-job/b8bca95f25 --- frappe/core/doctype/user_type/user_type.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/core/doctype/user_type/user_type.py b/frappe/core/doctype/user_type/user_type.py index 5917ba2756..39d9133412 100644 --- a/frappe/core/doctype/user_type/user_type.py +++ b/frappe/core/doctype/user_type/user_type.py @@ -287,7 +287,7 @@ def user_linked_with_permission_on_doctype(doc, user): def apply_permissions_for_non_standard_user_type(doc, method=None): """Create user permission for the non standard user type""" - if not frappe.db.table_exists("User Type"): + if not frappe.db.table_exists("User Type") or frappe.flags.in_migrate: return user_types = frappe.cache().get_value( From 391edba10a58f9046c2b4eeb39e380b38af490cd Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 23 Jan 2023 15:27:57 +0530 Subject: [PATCH 2/2] fix(UX): better error message for dead link fields Link fields referring to non-existing doctypes are possible when - Removing customizations. - Removing app which added a custom field but didn't clean up after itself. [skip ci] --- frappe/desk/form/meta.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/frappe/desk/form/meta.py b/frappe/desk/form/meta.py index b5b58ebfa3..d6ff71b367 100644 --- a/frappe/desk/form/meta.py +++ b/frappe/desk/form/meta.py @@ -4,6 +4,7 @@ import io import os import frappe +from frappe import _ from frappe.build import scrub_html_template from frappe.model.meta import Meta from frappe.model.utils import render_include @@ -182,21 +183,38 @@ class FormMeta(Meta): def add_search_fields(self): """add search fields found in the doctypes indicated by link fields' options""" + # TODO: IF field is not found replace with useful message for df in self.get("fields", {"fieldtype": "Link", "options": ["!=", "[Select]"]}): if df.options: - search_fields = frappe.get_meta(df.options).search_fields + try: + search_fields = frappe.get_meta(df.options).search_fields + except frappe.DoesNotExistError: + self._show_missing_doctype_msg(df) + if search_fields: search_fields = search_fields.split(",") df.search_fields = [sf.strip() for sf in search_fields] + def _show_missing_doctype_msg(self, df): + # A link field is referring to non-existing doctype, this usually happens when + # customizations are removed or some custom app is removed but hasn't cleaned + # up after itself. + frappe.clear_last_message() + customize_form_link = f'Customize Form' + frappe.throw( + _( + "Field {0} is referring to non-existing doctype {1}, please remove the field from {2} or add the required doctype." + ).format(frappe.bold(df.fieldname), frappe.bold(df.options), customize_form_link), + title=_("Missing DocType"), + ) + def add_linked_document_type(self): for df in self.get("fields", {"fieldtype": "Link"}): if df.options: try: df.linked_document_type = frappe.get_meta(df.options).document_type except frappe.DoesNotExistError: - # edge case where options="[Select]" - pass + self._show_missing_doctype_msg(df) def load_print_formats(self): print_formats = frappe.db.sql(