Maximum call stack size exceeded

I am building a backend routine to renew a tutor subscription (my own code, not using the Wix payment plans app) and no matter how I organize the front and backend code I keep getting a “Maximum call stack size exceeded” error, which I assume it is the result of a poorly structured async/await or .then sequence.

I’m using the standard Wix Editor in Dev mode.

I’ve stripped down the code here to the relevant function and backend call, and even with this I’m still getting the call stack error. (No line is indicated in the console, but the error appears to come on the final update call, and sometimes earlier as well.)

FrontEnd (relevant function only):

async function RenewPlan(planHandle){// _id of the item to renew in PlanPurchases Db
let planOrderNumber = 12345 // for testing only

let orderDataPaid = await RenewTutorPlan(planHandle, planOrderNumber);
}  

Backend: complete RewewTutorPlan.jsw

import wixData from "wix-data";

export async function RenewTutorPlan(pHandle, order) {

let itemInsert = await wixData.get("PlanPurchases", pHandle);
itemInsert.planStatus = "PENDING"; 
itemInsert.planExpires = "Dec. 31"; 
itemInsert.planExpiresValue = "241231"; 
  
let renewed = await wixData.update("PlanPurchases", itemInsert);
return renewed
}

The call stack size error does not seem to stem from this piece of code, nothing here calls itself repeatedly

Do you perhaps have the actual call stack that came with the error? And, other code running on that page?

I was preparing to post more details and realized I’d inadvertently removed a key line while stripping down the backend code down to post last time. It should be:

import wixData from "wix-data";

export async function RenewTutorPlan(pHandle, order) {

let itemInsert = await wixData.get("PlanPurchases", pHandle);
itemInsert.planStatus = "PENDING"; 
itemInsert.planExpires = "Dec. 31"; 
itemInsert.planExpiresValue = "241231"; 
itemInsert.purchaseData = itemInsert;
  
let renewed = await wixData.update("PlanPurchases", itemInsert);
return renewed
}

It appears that the line itemInsert.purchaseData = itemInsert; was triggering the stack error.

Similar to Wix Payment Plans, when a plan is purchased I write an array object containing all the original purchase data in the PlanPurchases Db (field type set as object). Upon renewing the plan I am trying to update that array object with the modified itemInsert data (new status, expiry date, etc).

I can see why inserting an array into one of its array elements would cause errors. Do you have any suggestions on how to update the purchaseData field to include the renewal data?