"Could not find field" When Setting Up A Document Link to a Document with a Child Table
See original GitHub issueDescription of the issue
This is related to #14420 insofar as the reason for writing both bug reports is the same. While that specific issue (AttributeError) was solved, the overarching problem still exists: specifically, you still can’t set up Linked Documents to Link fields in Child Tables using the DocType interface. While this isn’t an easy issue to explain, the issue should be easy to reproduce by attempting to create a connection on a doctype to a document based on a field in the document’s child table.
Say I have a Doctype HostDocType
which has a Table Field called the_child_table
with the Doctype ChildDocType
. This DocType has a Link Field called link_to_subject_docType
, which naturally links to a third doctype called SubjectDocType
. The hierarchy looks something like this:
HostDocType
the_child_table (ChildDocType)
link_to_subject_docType -> SubjectDocType
I want to set up a “Linked Document” on SubjectDocTypeto relevant HostDocType documents. So I fill out the Linked Documents field in the following manner:
Link DocType: ChildDocType Link FIeldname: link_to_subject_docType Parent DocType: HostDocType Table Fieldname: the_child_table
When I hit save, I will get the following message:
Document Links Row #2: Could not find field the_child_table in SubjectDocType DocType
I’m not sure why its looking for the field in the DocType I’m attempting to place the connection on, but hey, maybe I reversed the fieldnames? So let’s try this:
Link DocType: ChildDocType Link FIeldname: the_child_table Parent DocType: HostDocType Table Fieldname: link_to_subject_docType
Now I get an error that looks correct:
Document Links Row #2: Could not find field the_child_table in ChildDocType DocType
So it is still isn’t possible to set up a Document Link to a document based on the contents of a Child Table.
Context information (for bug reports)
Output of bench version
ERPNext: v13.21.0 (version-13)
Frappe Framework: v13.21.0 (version-13)
Stacktrace / full error message
Traceback (most recent call last):
File "apps/frappe/frappe/app.py", line 68, in application
response = frappe.api.handle()
File "apps/frappe/frappe/api.py", line 55, in handle
return frappe.handler.handle()
File "apps/frappe/frappe/handler.py", line 31, in handle
data = execute_cmd(cmd)
File "apps/frappe/frappe/handler.py", line 68, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "apps/frappe/frappe/__init__.py", line 1213, in call
return fn(*args, **newargs)
File "apps/frappe/frappe/desk/form/save.py", line 21, in savedocs
doc.save()
File "apps/frappe/frappe/model/document.py", line 287, in save
return self._save(*args, **kwargs)
File "apps/frappe/frappe/model/document.py", line 324, in _save
self.run_before_save_methods()
File "apps/frappe/frappe/model/document.py", line 971, in run_before_save_methods
self.run_method("validate")
File "apps/frappe/frappe/model/document.py", line 869, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File "apps/frappe/frappe/model/document.py", line 1161, in composer
return composed(self, method, *args, **kwargs)
File "apps/frappe/frappe/model/document.py", line 1144, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File "apps/frappe/frappe/model/document.py", line 863, in <lambda>
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File "apps/frappe/frappe/core/doctype/doctype/doctype.py", line 82, in validate
validate_links_table_fieldnames(self)
File "apps/frappe/frappe/core/doctype/doctype/doctype.py", line 740, in validate_links_table_fieldnames
frappe.throw(message, InvalidFieldNameError, _("Invalid Fieldname"))
File "apps/frappe/frappe/__init__.py", line 444, in throw
msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable, wide=wide, as_list=as_list)
File "apps/frappe/frappe/__init__.py", line 423, in msgprint
_raise_exception()
File "apps/frappe/frappe/__init__.py", line 378, in _raise_exception
raise raise_exception(msg)
frappe.core.doctype.doctype.doctype.InvalidFieldNameError: Document Links Row #2: Could not find field <b>the_child_table</b> in <b>CustomDocType</b> DocType
Additional information
Original bug report was here: #14420
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (7 by maintainers)
Top GitHub Comments
Not fully resolved, as per https://github.com/frappe/frappe/pull/16050#issuecomment-1062239956
I think there may be a different problem then. I did notice your instructions, but I assumed that I knew what I was doing. However, after actually following them I got it to work, but the form doesn’t work the way I expected and there may be other issues with this approach.
This is what I mean:
The form has a “Is Child Table” readonly checkbox. It is automatically checked when the
Link Doctype
field contains the name of a child table DocType, and two additional fields will appear at the same time:Parent DocType
andTable Fieldname
:However, your instructions ignores those fields and has the user select the main DocType under the
Link Doctype
field, and fill in theLink Fieldname
with the child table field. This works, but it gives me pause because I’m not being very specific about what fields I want to connect (is that by intent?). What happens if the child table has a field with the same name as the parent DocType? Would the connection find both links, would it raise an SQL exception…?If this is correct behavior and it works, the additional fields related to “Child Table” should probably be removed so they don’t confuse people. Otherwise, I think we might need to think about this some more.