Dict' object has no attribute 'update_if_missing'

Hello everybody
Trying to insert into my custom doctype using python script opens json file then insert each record into database but i got this error

File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 219, in insert
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 627, in _set_defaults
AttributeError: ‘dict’ object has no attribute ‘update_if_missing’

my code snippet:

    def execute():
    	with open(os.path.join(sys.path[0], "/home/frappe/frappe- 
            bench/apps/custom/custom_app/patches/mapping.json"), "r") as f:
    		data = json.load(f)
    		for x in data['feature_mapping']:
    			print (x['feature'])
    				"doctype": "Mapping",
    			if x['allow_totp']=='Yes':
    			doc.insert( ignore_permissions=True, # ignore write permissions during insert
    					    ignore_links=True, # ignore Link validation in the document
    					    ignore_if_duplicate=True, # dont insert if DuplicateEntryError is thrown

@Zeinab_Mohammed have you solved this. i am also facing same error

@abrarpv97 @Zeinab_Mohammed How have you solved this ?

I think what you want to do is insert an element in a table when you do :


Which it does not seems to be the good way to do it. Try to insert your elements like this :

    "doctype": "Mapping",
doc.roles = []
doc.append("roles", {YOUR ROLE OBJECT})

Repeat this workflow for every table in your document (initialize => append).

Hope this will help.

1 Like

this solution is working thanks. but the problem i have faced was AttributeError: 'dict' object has no attribute 'is_new'. so