Doc.insert() not working from Server Script

Hi All

I have a Server Script set as a API method.
I call this method to insert a new “Currency Exchange” record

data = {'doctype':'Currency Exchange',
        'date':date,
        'exchange_rate':exchange_rate,
        'from_currency':'USD',
        'to_currency':'GTQ',
        'for_buying':1,
        'for_selling':1} 

name = date+'-USD-GTQ-Selling-Buying'

if not frappe.db.exists('Currency Exchange',name):
    doc = frappe.get_doc(data).insert(ignore_permissions = True)
else:
    doc = {'message':'Exchange Rate Record Already Exists'}
    
frappe.response['doc'] = doc

When I call this api I get the inserted record with name assigned and creation date-time
I look at the Currency Exchange List in ERPNext and record is not there.
I call the api again and I get the same record with same name but different creation date-time
again document is not in the list in ERPNext

There is no commit() function on the Document Api
Do I need to call frappe.db.commit() ?

When I call the frappe.db.commit() it inserts the record but this is not required according to documentation and examples…

Thanks in advance

1 Like

I have the same issue

Was this ever solved? I’m having the exact same issue currently