From aa476701ace9be77d67d3cbc11ee398ed86a95cc Mon Sep 17 00:00:00 2001 From: Henry Fontanier Date: Wed, 24 Jan 2024 18:01:40 +0100 Subject: [PATCH] delete table if rows upsert fails --- .../w/[wId]/data_sources/[name]/tables/csv.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/front/pages/api/w/[wId]/data_sources/[name]/tables/csv.ts b/front/pages/api/w/[wId]/data_sources/[name]/tables/csv.ts index 7039dd283393..c489e4b1abff 100644 --- a/front/pages/api/w/[wId]/data_sources/[name]/tables/csv.ts +++ b/front/pages/api/w/[wId]/data_sources/[name]/tables/csv.ts @@ -175,6 +175,25 @@ async function handler( "Failed to upsert rows." ); + const delRes = await coreAPI.deleteTable({ + projectId: dataSource.dustAPIProjectId, + dataSourceName: dataSource.name, + tableId, + }); + + if (delRes.isErr()) { + logger.error( + { + dataSourceName: dataSource.name, + workspaceId: owner.id, + tableId, + tableName: name, + error: delRes.error, + }, + "Failed to delete table after failed upsert." + ); + } + return apiError(req, res, { status_code: 500, api_error: {