Merge pull request #19725 from ankush/migration_fixes_moar

fix: misc migration issues
This commit is contained in:
Ankush Menat 2023-01-23 16:44:19 +05:30 committed by GitHub
commit 3821167f66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View file

@ -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(

View file

@ -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'<a href="/app/customize-form/?doc_type={self.name}">Customize Form</a>'
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(