fix(Virtual DocType): don't call db get_value in link field validation (#23620)

* fix(Virtual DocType): use get_doc to validate link field instead of db get_value

* refactor: use is_virtual_doctype util & always return a dict
This commit is contained in:
Md Hussain Nagaria 2023-12-07 21:58:05 +05:30 committed by GitHub
parent 2522cbf6ab
commit cfc781e5b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,6 +10,7 @@ import frappe.utils
from frappe import _
from frappe.desk.reportview import validate_args
from frappe.model.db_query import check_parent_permission
from frappe.model.utils import is_virtual_doctype
from frappe.utils import get_safe_filters
from frappe.utils.deprecations import deprecated
@ -431,6 +432,18 @@ def validate_link(doctype: str, docname: str, fields=None):
)
values = frappe._dict()
if is_virtual_doctype(doctype):
try:
frappe.get_doc(doctype, docname)
values.name = docname
except frappe.DoesNotExistError:
frappe.clear_last_message()
frappe.msgprint(
_("Document {0} {1} does not exist").format(frappe.bold(doctype), frappe.bold(docname)),
)
return values
values.name = frappe.db.get_value(doctype, docname, cache=True)
fields = frappe.parse_json(fields)