Document attached to child table must be a dict or BaseDocument, not class 'str'

I want to insert data in a doctype and it’s child table using frappeClient

    links_dict = {
            "doctype": "Dynamic Link",
            "link_doctype": 'customer',
            "link_name": dc['name'],#get customer name 
            } 
    doc = {
    "doctype": "Address",
    "address_title": dc['display_name'],
    "address_type": add_type,
    "email_id": dc['email'],
    "phone": dc['phone'],
    "city": cty,
    "country": get_territory(dc['country_id']), #get country,
    "address_line1": dc['street'],
    "address_line2":dc['street2'],
    "state":get_state(dc['state_id']),#get state,
    "is_your_company_address":False,
    "links": links_dic
    } 
if doc['address_title'] in add_check:
            doc['address_title'] += str(dc['id'])
    client.insert(doc)

Getting "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 class 'str’

some people suggested using self.append() but it will not work here.

Child table must be a list of dictionaries like
links_dict =[
{
“doctype”: “Dynamic Link”,
“link_doctype”: ‘customer’,
“link_name”: dc[‘name’],#get customer name
},
{
“doctype”: “Dynamic Link2”,
“link_doctype”: ‘customer2’,
“link_name”: dc[‘name’],#get customer name
},
]

1 Like

Thanks @ahmed-madi It helps me a lot :slight_smile: