Document attached to child table must be a dict or BaseDocument, not type 'list' [SOLVED]

Hi,
I have a child table shown below:

Field Name Data Type Option
code data
PRODUCT data
VARIATION Link Item Alternate Option

I select any value from the variation link, it get passed to a python function along with the item code and returns an item code, I am just updating the value of field code with the item code returned, but it doesn’t allow me to save and give the below error:

Traceback (most recent call last):
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 12, in savedocs
    doc = frappe.get_doc(json.loads(doc))
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/__init__.py", line 606, in get_doc
    return frappe.model.document.get_doc(arg1, arg2)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/document.py", line 51, in get_doc
    return controller(arg1, arg2)
  File "/home/vishnu/frappe-bench/apps/erpnext/erpnext/selling/doctype/sales_order/sales_order.py", line 25, in __init__
    super(SalesOrder, self).__init__(arg1, arg2)
  File "/home/vishnu/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py", line 20, in __init__
    super(AccountsController, self).__init__(arg1, arg2)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/document.py", line 87, in __init__
    super(Document, self).__init__(arg1)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 52, in __init__
    self.update(d)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 75, in update
    self.set(key, value)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 122, in set
    self.extend(key, value)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 148, in extend
    self.append(key, v)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 136, in append
    value = self._init_child(value, key)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 163, in _init_child
    value = get_controller(value["doctype"])(value)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/document.py", line 87, in __init__
    super(Document, self).__init__(arg1)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 52, in __init__
    self.update(d)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 75, in update
    self.set(key, value)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 122, in set
    self.extend(key, value)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 148, in extend
    self.append(key, v)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 143, in append
    raise ValueError, "Document attached to child table must be a dict or BaseDocument, not " + str(type(value))[1:-1]
ValueError: Document attached to child table must be a dict or BaseDocument, not type 'list'
Traceback (most recent call last):
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/app.py", line 56, in application
    response = frappe.handler.handle()
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/handler.py", line 19, in handle
    execute_cmd(cmd)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/handler.py", line 42, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/__init__.py", line 907, in call
    return fn(*args, **newargs)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 12, in savedocs
    doc = frappe.get_doc(json.loads(doc))
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/__init__.py", line 606, in get_doc
    return frappe.model.document.get_doc(arg1, arg2)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/document.py", line 51, in get_doc
    return controller(arg1, arg2)
  File "/home/vishnu/frappe-bench/apps/erpnext/erpnext/selling/doctype/sales_order/sales_order.py", line 25, in __init__
    super(SalesOrder, self).__init__(arg1, arg2)
  File "/home/vishnu/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py", line 20, in __init__
    super(AccountsController, self).__init__(arg1, arg2)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/document.py", line 87, in __init__
    super(Document, self).__init__(arg1)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 52, in __init__
    self.update(d)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 75, in update
    self.set(key, value)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 122, in set
    self.extend(key, value)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 148, in extend
    self.append(key, v)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 136, in append
    value = self._init_child(value, key)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 163, in _init_child
    value = get_controller(value["doctype"])(value)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/document.py", line 87, in __init__
    super(Document, self).__init__(arg1)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 52, in __init__
    self.update(d)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 75, in update
    self.set(key, value)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 122, in set
    self.extend(key, value)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 148, in extend
    self.append(key, v)
  File "/home/vishnu/frappe-bench/apps/frappe/frappe/model/base_document.py", line 143, in append
    raise ValueError, "Document attached to child table must be a dict or BaseDocument, not " + str(type(value))[1:-1]
ValueError: Document attached to child table must be a dict or BaseDocument, not type 'list'

Regards
Ruchin Sharna

The above problem has been solved, and the issue was I was passing a list from the python function instead of a single value or a dict and with that I was trying to update a text field.

Regards
Ruchin Sharma

1 Like

@ruchin78 I was with the same Issue, Thank you.

Kindly share your code for adding data to Child Table, it would be of great help.
@ruchin78 and @Thiago_Henry
Thanks in advance.

Here is my python method. Employee is the parent Doctype, Employee Education is the Child and employee_edu contains the information i want to append to Employee Education. @Thiago_Henry @ruchin78 Kindly assist me
@frappe.whitelist()
def get_employee_educations(employee_edu, doc_name):
doc = frappe.get_doc(‘Employee’, doc_name);
employee_education = json.loads(employee_edu);
print(type(employee_education[‘education_qualification’][0]))
frappe.errprint("Employee New Edu – "+json.dumps(employee_education));
doc.append(“Employee Education”:employee_education[‘education_qualification’])
doc.save()
doc.submit()