From 66deebdf4e241c1685b3d953ceaeb66c7f800953 Mon Sep 17 00:00:00 2001 From: Yulian Diaz <5605867+spatialy@users.noreply.github.com> Date: Wed, 25 Feb 2026 10:56:57 -0500 Subject: [PATCH] fix(account): handle empty $in array to prevent PostgreSQL IN () syntax error (#10554) * fix(account): handle empty array in $in SQL clause to prevent PostgreSQL syntax error buildWhereClause now emits FALSE for empty $in arrays instead of invalid IN () syntax. Also adds an early return in getWorkspacesInfoWithStatusByIds so callers like the GitHub/Gmail/Backup services never hit the query with an empty uuid list. Fixes #10553 Signed-off-by: Yulian Diaz <5605867+spatialy@users.noreply.github.com> * fix(account): also guard against non-array uuids in getWorkspacesInfoWithStatusByIds Per review feedback from @ArtyomSavchenko: use Array.isArray() in addition to the length check to handle runtime cases where uuids may not be an array. Signed-off-by: Yulian Diaz <5605867+spatialy@users.noreply.github.com> --------- Signed-off-by: Yulian Diaz <5605867+spatialy@users.noreply.github.com> --- server/account/src/collections/postgres/postgres.ts | 4 ++++ server/account/src/utils.ts | 1 + 2 files changed, 5 insertions(+) diff --git a/server/account/src/collections/postgres/postgres.ts b/server/account/src/collections/postgres/postgres.ts index 4bb1b8e019..53bc5f98ba 100644 --- a/server/account/src/collections/postgres/postgres.ts +++ b/server/account/src/collections/postgres/postgres.ts @@ -176,6 +176,10 @@ implements DbCollection { switch (operator) { case '$in': { const inVals = Object.values(qKey as object)[0] + if (inVals.length === 0) { + whereChunks.push('FALSE') + break + } const inVars: string[] = [] for (const val of inVals) { currIdx++ diff --git a/server/account/src/utils.ts b/server/account/src/utils.ts index bb9497f5c9..ab6103bbba 100644 --- a/server/account/src/utils.ts +++ b/server/account/src/utils.ts @@ -1351,6 +1351,7 @@ export async function getWorkspacesInfoWithStatusByIds ( db: AccountDB, uuids: WorkspaceUuid[] ): Promise { + if (!Array.isArray(uuids) || uuids.length === 0) return [] const statuses = await db.workspaceStatus.find({ workspaceUuid: { $in: uuids } }) const statusesMap = statuses.reduce>((sm, s) => { sm[s.workspaceUuid] = s