Deferred_insert not work

hello every one, when i use deferred_insert to bulk create record, it print “ok” but nothing insert on database. tks

Hi @meeeeeeeee ,

deferred_insert doesn’t insert data directly in database, instead stores temporarily it in cache and insert later.

And also it doesn’t guarantee insertion.

@Ninad1306 i know, it use redis queue but i just test only 2 record and do not see the database update

Are you running this function as some background job or in bench console for testing??

@Ninad1306 i used bench console then check redis cache by : redis-cli -p 13000 and i saw key “insert_queue_for_Histories” .
I also was check in insert_record() and it ok but nothing insert in db.

Do I need configuration anything for rq job auto run

If you use bench console then you have to explicitly commit your changes using frappe.db.commit, else they will not reflect in database.

Try committing the changes once and then if any problem faced then i can help.

If you don’t use bench console then after a request, frappe ends a transaction by committing the changes, but in console you are running the function so you have to explicitly commit the changes.

And this applies to any changes made to database in bench console.

i used frappe.db.commit() but still not work. and somtime i got this althought i set permitions for doctype is guest with write role

This error message suggest that you need create permission, which would have not been given.

And also you don’t have to write commit in your function, you can do it this way,


it still not work and i check the redis cache. when i get key, the log has generate. I don’t know if this is the problem. i log for everythiing all is ok but not update in database


this is all log, every thing ok but not have record inserted

@meeeeeeeee I tried out different possibilities that why would it not insert even though no error is shown.

Then I tried inserting a record without specifying a mandatory field or wrong type for the field value, and then even though no error was thrown, record was no inserted.

So, maybe this will be the case with you that you must not be specifying some mandatory field or wrong type for field value.

@Ninad1306 yes, thank you so much, some fields in the doctype do not match the data I inserted.
But why doesn’t it show errors? This causes difficulty in the programming process. :smile: