Payment Registering not working after latest update 15.121.6

The current version of what we are using is

{
	"frappe": "15.121.3",
	"erpnext": "15.121.6",
	"our_app": "0.0.1"
}

After doing the latest erpnext latest update, payment register from an app does not seem to be working.

https://www.cve.org/CVERecord?id=CVE-2026-72910

I am aware that it was a breaking update and I understand that it is needed for security reasons.

I need help to change the suspected part of the code below. I think “ignore_permissions=True” is the problem.

How to make it do with the permission like “System Manager” for example?

        so_doc.save(ignore_permissions=True)
        frappe.db.commit()

        # Update sales invoice with payment response
        si.append("custom_transaction_response", {
            "payment_response": str(payment_response),
            "transaction_date": str(getdate())
        })
        
        si.save(ignore_permissions=True)
        si.submit()
        frappe.msgprint("Sales Invoice submitted")
        scheduler_logger.info(f"Sales Invoice submitted")

        # Create payment entry
        pe = get_payment_entry(dt="Sales Invoice", dn=si.name)
        pe.reference_no = "1"
        pe.reference_date = si.posting_date
        pe.insert(ignore_permissions=1)
        pe.submit()
        frappe.msgprint("Payment Made")
        scheduler_logger.info(f"Payment Made, adding payment entry to Sales Invoice")

Need advice on how to solve this. Please help.

Got the following possible solution from Google search Ai. Tried it and it is working on the test system.

Is this the correct way to fix the problem?

# Save the current user so you can restore it later
original_user = frappe.session.user

try:
    # Switch context to the target user
    frappe.set_user("[email protected]")
    
    # Retrieve and save the document
    doc = frappe.get_doc("ToDo", "TODO-00001")
    doc.description = "Updated description"
    doc.save() # Permissions and validations will be enforced for this user

finally:
    # Always restore the original user session context
    frappe.set_user(original_user)

When applied the above to my code, it is like this.

        # Save the current user so you can restore it later
        original_user = frappe.session.user

        try:
                # Switch context to the target user
                frappe.set_user("[email protected]")

                # Create payment entry
                pe = get_payment_entry(dt="Sales Invoice", dn=si.name)
                pe.reference_no = "1"
                pe.reference_date = si.posting_date
                pe.insert()
                pe.submit()
                frappe.msgprint("Payment Made")
                scheduler_logger.info(f"Payment Made, adding payment entry to Sales Invoice")

        finally:
                # Always restore the original user session context
                frappe.set_user(original_user)

Please share your comments and advice.