Frappe.db.commit() has no effect

try:
{my code here}
doc.submit()
{another code}

frappe.db.commit()
    except Exception as e:
        frappe.db.rollback()
        raise
    return "ok"

I have following code for my custom API, but why if there is an error after “doc.submit()” all the changes doesn’t rollback and it persist on my database?
Am I doing it wrong?

@oscarutomo Did you defined “doc” ?
Provide whole code if possible!

    try:        
        closing_entry = frappe.new_doc("POS Closing Entry")
        closing_entry.period_start_date = raw_closing_entry.period_start_date
        closing_entry.period_end_date = raw_closing_entry.period_end_date
        closing_entry.posting_date = raw_closing_entry.posting_date
        closing_entry.posting_time = raw_closing_entry.posting_time
        closing_entry.pos_opening_entry = raw_closing_entry.pos_opening_entry
        closing_entry.company = raw_closing_entry.company
        closing_entry.pos_profile = raw_closing_entry.pos_profile
        closing_entry.user = raw_closing_entry.user
        closing_entry.pos_transactions = raw_closing_entry.pos_transactions
        closing_entry.grand_total = raw_closing_entry.grand_total
        closing_entry.net_total = raw_closing_entry.net_total
        closing_entry.total_quantity = raw_closing_entry.total_quantity
        closing_entry.taxes = raw_closing_entry.taxes
         closing_entry.save(ignore_permissions=True)
        closing_entry.submit()
        frappe.db.commit()
    except Exception as e:
        frappe.db.rollback()
        raise
    return "ok"

here is my whole code

What is the error you are getting?

Hi, sorry just replied.

I’m facing no error in my code, but i’m doing an experiment that after my “closing_entry.submit()” and before “frappe.db.commit()” I raise an error.

Expected behaviour is all my closing entry should be rollback. But in fact, the data is still there so actually with or without frappe.db.commit(), my data is auto commited straight away.

Do you know what the cause?