SQL Query via Background Job not getting latest db value

Hi,

I’m using V12 production
I made a function which is placed on on_submit and on_cancel hook.

the function is simply getting latest item qty.

def get_stock_qty(self, method):
	from erpnext.stock.utils import get_latest_stock_qty
	for d in self.items:
		actual_qty = get_latest_stock_qty(item_code=d.item_code, warehouse=d.warehouse) 
		print(self.name, method, d.item_code, actual_qty)

def doc_on_submit_cancel(self, method):
	get_stock_qty(self, method)

	frappe.enqueue("test1.test1.test1.get_stock_qty")

The result is different when running doc_on_submit_cancel where direct get_stock_qty resulting latest qty (means the db change is committed) after submitted but frappe.enqueue resulting value before submission.

If I set is_aync=False to frappe.enqueue then it’s executed with latest value.
So the problem occurs if the fucntion is run via worker

Why? Please any body who has any clues?

My use case I want to run the function via background worker for further processing

Thanks

1 Like

Just got solution, set parameter enqueue_after_submit=True

1 Like