From b0eaac5b8480cae92d2b98524dd60e0e1eb0bc70 Mon Sep 17 00:00:00 2001 From: vchske Date: Fri, 9 Dec 2022 15:14:46 -0800 Subject: [PATCH] =?UTF-8?q?Fixes=20issue=20where=20empty=20partition=20key?= =?UTF-8?q?=20is=20treated=20like=20nonexistent=20key=E2=80=A6=20(#1359)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/dataAccess/deleteDocument.ts | 2 +- src/Common/dataAccess/readDocument.ts | 3 +-- src/Common/dataAccess/updateDocument.ts | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Common/dataAccess/deleteDocument.ts b/src/Common/dataAccess/deleteDocument.ts index 51713e791..9f4565c94 100644 --- a/src/Common/dataAccess/deleteDocument.ts +++ b/src/Common/dataAccess/deleteDocument.ts @@ -13,7 +13,7 @@ export const deleteDocument = async (collection: CollectionBase, documentId: Doc await client() .database(collection.databaseId) .container(collection.id()) - .item(documentId.id(), documentId.partitionKeyValue?.length === 0 ? undefined : documentId.partitionKeyValue) + .item(documentId.id(), documentId.partitionKeyValue?.length === 0 ? "" : documentId.partitionKeyValue) .delete(); logConsoleInfo(`Successfully deleted ${entityName} ${documentId.id()}`); } catch (error) { diff --git a/src/Common/dataAccess/readDocument.ts b/src/Common/dataAccess/readDocument.ts index 6e826b041..4ff63dfb6 100644 --- a/src/Common/dataAccess/readDocument.ts +++ b/src/Common/dataAccess/readDocument.ts @@ -21,8 +21,7 @@ export const readDocument = async (collection: CollectionBase, documentId: Docum const response = await client() .database(collection.databaseId) .container(collection.id()) - // use undefined if the partitionKeyValue is empty - .item(documentId.id(), documentId.partitionKeyValue?.length === 0 ? undefined : documentId.partitionKeyValue) + .item(documentId.id(), documentId.partitionKeyValue?.length === 0 ? "" : documentId.partitionKeyValue) .read(options); return response?.resource; diff --git a/src/Common/dataAccess/updateDocument.ts b/src/Common/dataAccess/updateDocument.ts index 8aa100bbc..350bfc734 100644 --- a/src/Common/dataAccess/updateDocument.ts +++ b/src/Common/dataAccess/updateDocument.ts @@ -25,7 +25,7 @@ export const updateDocument = async ( const response = await client() .database(collection.databaseId) .container(collection.id()) - .item(documentId.id(), documentId.partitionKeyValue?.length === 0 ? undefined : documentId.partitionKeyValue) + .item(documentId.id(), documentId.partitionKeyValue?.length === 0 ? "" : documentId.partitionKeyValue) .replace(newDocument, options); logConsoleInfo(`Successfully updated ${entityName} ${documentId.id()}`);