From 486c29bdd41d1bbb35bf6d59959e5e2b8a3d7fa4 Mon Sep 17 00:00:00 2001 From: Mert E Date: Fri, 14 Jun 2024 14:05:27 +0300 Subject: [PATCH] fix: missing pk handling (#8749) * fix: handle null case * fix: missing required field --- packages/nocodb/src/db/BaseModelSqlv2.ts | 7 ++++--- packages/nocodb/src/helpers/catchError.ts | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 67511ab211..88daac903f 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -7504,10 +7504,11 @@ export function _wherePk( } export function getCompositePkValue(primaryKeys: Column[], row) { - if (typeof row !== 'object') return row; - - if (row === null) + if (row === null || row === undefined) { NcError.requiredFieldMissing(primaryKeys.map((c) => c.title).join(',')); + } + + if (typeof row !== 'object') return row; return primaryKeys.map((c) => row[c.title] ?? row[c.column_name]).join('___'); } diff --git a/packages/nocodb/src/helpers/catchError.ts b/packages/nocodb/src/helpers/catchError.ts index 86bb0e37fb..b43c46b39e 100644 --- a/packages/nocodb/src/helpers/catchError.ts +++ b/packages/nocodb/src/helpers/catchError.ts @@ -670,7 +670,9 @@ export class NcError { id: string | string[] | Record | Record[], args?: NcErrorArgs, ) { - if (typeof id === 'string') { + if (!id) { + id = 'unknown'; + } else if (typeof id === 'string') { id = [id]; } else if (Array.isArray(id)) { if (id.every((i) => typeof i === 'string')) {