From a427d990a11eea5910526b378e4cd70b8a5e5aba Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 10 Nov 2023 11:58:07 +0000 Subject: [PATCH] Quick addition - if the object has been deleted but the key is still known, then CouchDB will alert us to the fact that it is deleted, leaving the response in a weird state. --- packages/backend-core/src/db/couch/DatabaseImpl.ts | 14 +++++++++++--- packages/backend-core/src/redis/redis.ts | 1 - 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/backend-core/src/db/couch/DatabaseImpl.ts b/packages/backend-core/src/db/couch/DatabaseImpl.ts index 6a1e575ac9..8588a7157a 100644 --- a/packages/backend-core/src/db/couch/DatabaseImpl.ts +++ b/packages/backend-core/src/db/couch/DatabaseImpl.ts @@ -10,6 +10,7 @@ import { DatabaseDeleteIndexOpts, Document, isDocument, + RowResponse, } from "@budibase/types" import { getCouchInfo } from "./connections" import { directCouchUrlCall } from "./utils" @@ -127,12 +128,19 @@ export class DatabaseImpl implements Database { keys: ids, include_docs: true, }) - const NOT_FOUND = "not_found" - const rows = response.rows.filter(row => row.error !== NOT_FOUND) + const rowUnavailable = (row: RowResponse) => { + // row is deleted - key lookup can return this + if (row.doc == null || ("deleted" in row.value && row.value.deleted)) { + return true + } + return row.error === "not_found" + } + + const rows = response.rows.filter(row => !rowUnavailable(row)) const someMissing = rows.length !== response.rows.length // some were filtered out - means some missing if (!opts?.allowMissing && someMissing) { - const missing = response.rows.filter(row => row.error === NOT_FOUND) + const missing = response.rows.filter(row => rowUnavailable(row)) const missingIds = missing.map(row => row.key).join(", ") throw new Error(`Unable to get documents: ${missingIds}`) } diff --git a/packages/backend-core/src/redis/redis.ts b/packages/backend-core/src/redis/redis.ts index 6f1b573718..701e262091 100644 --- a/packages/backend-core/src/redis/redis.ts +++ b/packages/backend-core/src/redis/redis.ts @@ -28,7 +28,6 @@ const DEFAULT_SELECT_DB = SelectableDatabase.DEFAULT // for testing just generate the client once let CLOSED = false let CLIENTS: { [key: number]: any } = {} -0 let CONNECTED = false // mock redis always connected