Skip to content

Commit

Permalink
fix(Virtual DocType): don't call db get_value in link field validation (
Browse files Browse the repository at this point in the history
#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

(cherry picked from commit cfc781e)
  • Loading branch information
NagariaHussain authored and mergify[bot] committed Dec 7, 2023
1 parent c65b4df commit 1d240a2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions frappe/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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

if TYPE_CHECKING:
Expand Down Expand Up @@ -435,6 +436,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)
Expand Down

0 comments on commit 1d240a2

Please sign in to comment.