diff --git a/frappe/core/doctype/file/file.py b/frappe/core/doctype/file/file.py index 34b8a606dd..16254da4cc 100755 --- a/frappe/core/doctype/file/file.py +++ b/frappe/core/doctype/file/file.py @@ -14,6 +14,7 @@ from requests.exceptions import HTTPError, SSLError import frappe from frappe import _ +from frappe.database.schema import SPECIAL_CHAR_PATTERN from frappe.model.document import Document from frappe.utils import call_hook_method, cint, get_files_path, get_hook_method, get_url from frappe.utils.file_manager import is_safe_path @@ -104,10 +105,7 @@ class File(Document): if not self.attached_to_name or not isinstance(self.attached_to_name, (str, int)): frappe.throw(_("Attached To Name must be a string or an integer"), frappe.ValidationError) - if not self.attached_to_field: - return - - if not frappe.get_meta(self.attached_to_doctype).has_field(self.attached_to_field): + if self.attached_to_field and SPECIAL_CHAR_PATTERN.search(self.attached_to_field): frappe.throw(_("The fieldname you've specified in Attached To Field is invalid")) def after_rename(self, *args, **kwargs): diff --git a/frappe/public/js/frappe/form/controls/attach.js b/frappe/public/js/frappe/form/controls/attach.js index 0f40a0a829..fc8aef72b8 100644 --- a/frappe/public/js/frappe/form/controls/attach.js +++ b/frappe/public/js/frappe/form/controls/attach.js @@ -79,7 +79,7 @@ frappe.ui.form.ControlAttach = class ControlAttach extends frappe.ui.form.Contro if (this.frm) { options.doctype = this.frm.doctype; options.docname = this.frm.docname; - options.fieldname = this.grid ? this.grid.df.fieldname : this.df.fieldname; + options.fieldname = this.df.fieldname; options.make_attachments_public = this.frm.meta.make_attachments_public; }