From d689ef889336577cd1aaee7374d58e4c0899c8fe Mon Sep 17 00:00:00 2001 From: Hardik Date: Mon, 18 May 2026 23:34:35 +0530 Subject: [PATCH] fix(vendors): fix transaction timeout and misleading error on vendor delete MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Increase the Prisma interactive transaction timeout from the default 5s to 30s so that the four sequential nullification + delete queries complete reliably on a seeded database (P2028 timeout was the root cause). Wrap the transaction in a try/catch so that if a timeout does still occur the user sees "Delete timed out — please try again." instead of an unhandled 500 that previously manifested as the misleading "referenced in submitted or active purchase orders" error message. Co-Authored-By: Claude Sonnet 4.6 --- App/app/(portal)/admin/vendors/actions.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/App/app/(portal)/admin/vendors/actions.ts b/App/app/(portal)/admin/vendors/actions.ts index 7247043..2e4e8ba 100644 --- a/App/app/(portal)/admin/vendors/actions.ts +++ b/App/app/(portal)/admin/vendors/actions.ts @@ -173,12 +173,23 @@ export async function deleteVendor(id: string): Promise { }); if (blocked) return { error: "Cannot delete: vendor is referenced in submitted or active purchase orders." }; - await db.$transaction(async (tx) => { - await tx.purchaseOrder.updateMany({ where: { vendorId: id, status: "DRAFT" }, data: { vendorId: null } }); - await tx.product.updateMany({ where: { lastVendorId: id }, data: { lastVendorId: null } }); - await tx.productVendorPrice.deleteMany({ where: { vendorId: id } }); - await tx.vendor.delete({ where: { id } }); - }); + try { + await db.$transaction( + async (tx) => { + await tx.purchaseOrder.updateMany({ where: { vendorId: id, status: "DRAFT" }, data: { vendorId: null } }); + await tx.product.updateMany({ where: { lastVendorId: id }, data: { lastVendorId: null } }); + await tx.productVendorPrice.deleteMany({ where: { vendorId: id } }); + await tx.vendor.delete({ where: { id } }); + }, + { timeout: 30000 }, + ); + } catch (err: unknown) { + const code = (err as { code?: string })?.code; + if (code === "P2028") { + return { error: "Delete timed out — please try again." }; + } + throw err; + } revalidatePath("/admin/vendors"); return { ok: true };