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>
This commit is contained in:
Yulian Diaz
2026-02-25 22:56:57 +07:00
committed by GitHub
parent 48a28a0b81
commit 66deebdf4e
2 changed files with 5 additions and 0 deletions
@@ -176,6 +176,10 @@ implements DbCollection<T> {
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++
+1
View File
@@ -1351,6 +1351,7 @@ export async function getWorkspacesInfoWithStatusByIds (
db: AccountDB,
uuids: WorkspaceUuid[]
): Promise<WorkspaceInfoWithStatus[]> {
if (!Array.isArray(uuids) || uuids.length === 0) return []
const statuses = await db.workspaceStatus.find({ workspaceUuid: { $in: uuids } })
const statusesMap = statuses.reduce<Record<string, WorkspaceStatus>>((sm, s) => {
sm[s.workspaceUuid] = s